实现父进程对子进程所使用的所有系统调用的追踪
ptrace.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct{
//根据系统调用号获取系统调用的符号名
long code;
char *sysCallName;
}SysCallTable;
SysCallTable sysCallTable[]={
//系统调用号和符号对应表
{
0, "read"},
{
1, "write"},
{
2, "open"},
{
3, "close"},
{
4, "stat"},
{
5, "fstat"},
{
6, "lstat"},
{
7, "poll"},
{
8, "lseek"},
{
9, "mmap"},
{
10, "mprotect"},
{
11, "munmap"},
{
12, "brk"},
{
13, "rt_sigaction"},
{
14, "rt_sigprocmask"},
{
15, "rt_sigreturn"},
{
16, "ioctl"},
{
17, "pread64"},
{
18, "pwrite64"},
{
19, "readv"},
{
20, "writev"},
{
21, "access"},
{
22, "pipe"},
{
23, "select"},
{
24, "sched_yield"},
{
25, "mremap"},
{
26, "msync"},
{
27, "mincore"},
{
28, "madvise"},
{
29, "shmget"},
{
30, "shmat"},
{
31, "shmctl"},
{
32, "dup"},
{
33, "dup2"},
{
34, "pause"},
{
35, "nanosleep"},
{
36, "getitimer"},
{
37, "alarm"},
{
38, "setitimer"},
{
39, "getpid"},
{
40, "sendfile"},
{
41, "socket"},
{
42, "connect"},
{
43, "accept"},
{
44, "sendto"},
{
45, "recvfrom"},
{
46, "sendmsg"},
{
47, "recvmsg"},
{
48, "shutdown"},
{
49, "bind"},
{
50, "listen"},
{
51, "getsockname"},
{
52, "getpeername"},
{
53, "socketpair"},
{
54, "setsockopt"},
{
55, "getsockopt"},
{
56, "clone"},
{
57, "fork"},
{
58, "vfork"},
{
59, "execve"},
{
60, "exit"},
{
61, "wait4"},
{
62, "kill"},
{
63, "uname"},
{
64, "semget"},
{
65, "semop"},
{
66, "semctl"},
{
67, "shmdt"},
{
68, "msgget"},
{
69, "msgsnd"},
{
70, "msgrcv"},
{
71, "msgctl"},
{
72, "fcntl"},
{
73, "flock"},
{
74, "fsync"},
{
75, "fdatasync"},
{
76, "truncate"},
{
77, "ftruncate"},
{
78, "getdents"},
{
79, "getcwd"},
{
80, "chdir"},
{
81, "fchdir"},
{
82, "rename"},
{
83, "mkdir"},
{
84, "rmdir"},
{
85, "creat"},
{
86, "link"},
{
87, "unlink"},
{
88, "symlink"},
{
89, "readlink"},
{
90, "chmod"},
{
91, "fchmod"},
{
92, "chown"},
{
93, "fchown"},
{
94, "lchown"},
{
95, "umask"},
{
96, "gettimeofday"},
{
97, "getrlimit"},
{
98, "getrusage"},
{
99, "sysinfo"},
{
100, "times"},
{
101, "ptrace"},
{
102, "getuid"},
{
103, "syslog"},
{
104, "getgid"},
{
105, "setuid"},
{
106, "setgid"},
{
107, "geteuid"},
{
108, "getegid"},
{
109, "setpgid"},
{
110, "getppid"},
{
111, "getpgrp"},
{
112, "setsid"},
{
113, "setreuid"},
{
114, "setregid"},
{
115, "getgroups"},
{
116, "setgroups"},
{
117, "setresuid"},
{
118, "getresuid"},
{
119, "setresgid"},
{
120, "getresgid"},
{
121, "getpgid"},
{
122, "setfsuid"},
{
123, "setfsgid"},
{
124, "getsid"},
{
125, "capget"},
{
126, "capset"},
{
127, "rt_sigpending"},
{
128, "rt_sigtimedwait"},
{
129, "rt_sigqueueinfo"},
{
130, "rt_sigsuspend"},
{
131, "sigaltstack"},
{
132, "utime"},
{
133, "mknod"},
{
134, "uselib"},
{
135, "personality"},
{
136, "ustat"},
{
137, "statfs"},
{
138, "fstatfs"},
{
139, "sysfs"},
{
140, "getpriority"},
{
141, "setpriority"},
{
142, "sched_setparam"},
{
143, "sched_getparam"},
{
144, "sched_setscheduler"},
{
145, "sched_getscheduler"},
{
146, "sched_get_priority_max"},
{
147, "sched_get_priority_min"},
{
148, "sched_rr_get_interval"},
{
149, "mlock"},
{
150, "munlock"},
{
151, "mlockall"},
{
152, "munlockall"},
{
153, "vhangup"},
{
154, "modify_ldt"},
{
155, "pivot_root"},
{
156, "_sysctl"},
{
157, "prctl"},
{
158, "arch_prctl"},
{
159, "adjtimex"},
{
160, "setrlimit"},
{
161,