Debian Codegraph @

testsuite/systemtap.syscall/forkwait.c

raw
1 /* COVERAGE: fork wait4 getpid getppid gettid */
2
3 #define _GNU_SOURCE
4 #include <sys/types.h>
5 #include <sys/time.h>
6 #include <sys/resource.h>
7 #include <sys/wait.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <sys/syscall.h>
11
12 int main ()
13 {
14 pid_t child;
15 int status;
16
17 child = fork();
18 #if !defined(__ia64__)
19 // Sometimes glibc substitutes a clone() call for a fork()
20 // call (verified with strace).
21 //staptest// [[[[fork ()!!!!clone (.+, XXXX, XXXX, XXXX)]]]] = NNNN
22 #else
23 // On RHEL5 ia64, fork() gets turned into clone2().
24 //staptest// [[[[fork ()!!!!clone2 (.+, XXXX, XXXX, XXXX, XXXX)]]]] = NNNN
25 #endif
26 if (!child) {
27 int i = 0xfffff;
28 while (i > 0) i--;
29 exit(0);
30 }
31 wait4(child, &status, WNOHANG, NULL);
32 //staptest// wait4 (NNNN, XXXX, WNOHANG, XXXX) = NNNN
33
34 // we need syscall() otherwise glibc would eliminate the system call
35 syscall(__NR_getpid);
36 //staptest// getpid () = NNNN
37
38 getppid();
39 //staptest// getppid () = NNNN
40
41 // Note: There is no glibc wrapper for this system call
42 syscall(__NR_gettid);
43 //staptest// gettid () = NNNN
44
45 return 0;
46 }