如何在C程序中连续检查ltrace命令输出 [英] How to continuously check ltrace command output in C program

查看:87
本文介绍了如何在C程序中连续检查ltrace命令输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用C程序捕获linux ltrace 命令的输出。



我尝试过使用popen()但是这不起作用,我需要不仅连续拍摄一次输出。



以下是我的代码:



请给我的建议



我的尝试:



Im trying to capture output of linux ltrace command using C program.

I have tried using popen() but that's not working, I need to capture continuously output not only once.

Below is my code:

Please give me your advice

What I have tried:

#include <stdio.h>
#include <stdlib.h>

int main(int carg, char *args[]) {
    FILE *fp = popen("ltrace -p pid", "r");
    char buf[255];
    while (1) {
        if (fgets(buf, 255, fp) != NULL) {
            printf("Captured Text: %s", buf);
        }
    }
    return 0;
}

推荐答案

我通过添加此
FILE *fp = popen("ltrace -p pid 2>&1", "r");

这是解决方案链接


这篇关于如何在C程序中连续检查ltrace命令输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆