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