Commit | Line | Data |
---|---|---|
48c56fcf PMF |
1 | #include <stdio.h> |
2 | #include <unistd.h> | |
cab68136 | 3 | #include <sys/types.h> |
909bc43f | 4 | #include <stdlib.h> |
48c56fcf | 5 | |
93d0f2ea | 6 | #include <ust/marker.h> |
48c56fcf | 7 | |
cab68136 | 8 | int main(int argc, char **argv, char *env[]) |
48c56fcf PMF |
9 | { |
10 | int result; | |
11 | ||
cab68136 PMF |
12 | if(argc < 2 ) { |
13 | fprintf(stderr, "usage: fork PROG_TO_EXEC\n"); | |
14 | exit(1); | |
15 | } | |
48c56fcf | 16 | |
cab68136 PMF |
17 | printf("Fork test program, parent pid is %d\n", getpid()); |
18 | trace_mark(ust, before_fork, MARK_NOARGS); | |
48c56fcf PMF |
19 | |
20 | result = fork(); | |
21 | if(result == -1) { | |
22 | perror("fork"); | |
23 | return 1; | |
24 | } | |
25 | if(result == 0) { | |
cab68136 PMF |
26 | char *args[] = {"fork2", NULL}; |
27 | ||
28 | printf("Child pid is %d\n", getpid()); | |
29 | ||
48c56fcf | 30 | trace_mark(ust, after_fork_child, MARK_NOARGS); |
cab68136 PMF |
31 | |
32 | trace_mark(ust, before_exec, "pid %d", getpid()); | |
33 | ||
34 | result = execve(argv[1], args, env); | |
35 | if(result == -1) { | |
36 | perror("execve"); | |
37 | return 1; | |
38 | } | |
39 | ||
40 | trace_mark(ust, after_exec, "pid %d", getpid()); | |
48c56fcf PMF |
41 | } |
42 | else { | |
43 | trace_mark(ust, after_fork_parent, MARK_NOARGS); | |
44 | } | |
45 | ||
46 | return 0; | |
47 | } |