新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 嵌入式系统中进程间通信的监视方法

嵌入式系统中进程间通信的监视方法

作者: 时间:2016-10-08 来源:网络 收藏
               #include sys/ptrace.h>
               #include sys/wait.h>
               #include linux/user.h>
               #include sys/socket.h>
               #include sys/un.h>
               #include linux/net.h>

为了在程序中使用 ptrace 系统调用,我们需要增加 ptrace.h 头文件。为了能够获得截获的系统调用的函数入参,我们需要使用 struct user_regs_struct 结构。它在 user.h 中被定义。由于在程序中使用了信号,因此,我们也需要 wait.h 。我们要监视通信动作, socket.h 和 un.h 则是必不可少的。

本文引用地址:https://www.eepw.com.cn/article/201610/305865.htm

下面是程序的入口主函数:

        int main (int argc, char *argv[])
        {
            int status;
            int syscall_entry = 0;
            int traced_process;
            struct user_regs_struct u_in;

status 用于记录被监视进程的状态变化; syscall_entry 记录被监视进程当前是进入系统调用,还是从系统调用中返回; u_in 用来获得截获的系统调用的参数; traced_process 则是被监视进程的 PID 值。

             traced_process = atoi(argv[1]); /* 从命令行得到监视进程的PID */
             ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);                           
				
            
                
			
							

关键词:

评论


相关推荐

技术专区