在Ubuntu18下安装strace(监视和跟踪系统调用的)

1. 在Ubuntu或Debian下安装就用apt-get install ,yum 一般用于centos中

2.遇到的问题:

(1)一般在下载安装新的东西之前先更新apt

apt-get update

报错:

Err:10 http://mirrors.aliyun.com/ubuntu raring Release
  404  Not Found [IP: 。。。。]

原因:源和系统的版本不匹配,或者源已被更新

解决:/etc/apt/sources.list的内容替换为以下:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

再执行更新即可成功

()apt-get strace E: Invalid operation strace

原因:忘了install

解决:

apt-get install strace

测试strace是否安装成功

        1.编写一个简单的源文件:  vi 123.c

#include <stdio.h>
int main(int argc, char **argv)
{
    printf("hello strace");   
    return 0;
 }  

        2.编译并测试:

gcc 123.c -o run
strace ./run

        3. 结果分析:   

 命令行输出执行该程序所调用的系统调用

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常感谢您的指正,我的回答中有误。以下是关于strace的正确介绍和使用方法: strace是一种调试工具,可以用来跟踪进程的系统调用以及接收和发送的信号。它可以用来定位程序的问题,例如执行错误的系统调用、I/O错误等等。下面介绍如何使用strace: 1. 安装strace 在大多数Linux发行版中,strace是默认安装的。如果您的系统中没有安装strace,可以使用以下命令进行安装: ``` sudo apt-get install strace ``` 2. 使用strace 使用strace非常简单,只需要在终端中输入strace命令,加上需要跟踪的进程ID即可。例如,假设需要跟踪进程ID为1234的进程,可以使用以下命令: ``` sudo strace -p 1234 ``` strace会输出进程执行的每个系统调用,以及调用时传递的参数和返回值。例如,以下是一个strace的输出示例: ``` open("/etc/passwd", O_RDONLY) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=2455, ...}) = 0 mmap(NULL, 2455, PROT_READ, MAP_SHARED, 3, 0) = 0x7f70a0346000 close(3) = 0 ``` 其中,每一行都是一个系统调用,以及调用时的参数和返回值。在上面的示例中,进程调用了open系统调用来打开/etc/passwd文件,然后使用fstat系统调用查询文件的状态,并使用mmap系统调用将文件映射到内存中,最后使用close系统调用关闭文件。 可以使用strace的不同选项来进行更详细的设置,例如使用“-t”选项来在输出中添加时间戳,使用“-e”选项来指定需要跟踪系统调用等等。具体可以参考strace的官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值