add missing licence headers
[ust.git] / tests / fork / fork.c
1 /* Copyright (C) 2009 Pierre-Marc Fournier
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17
18 #include <stdio.h>
19 #include <unistd.h>
20 #include <sys/types.h>
21 #include <stdlib.h>
22
23 #include <ust/marker.h>
24
25 int main(int argc, char **argv, char *env[])
26 {
27 int result;
28
29 if(argc < 2 ) {
30 fprintf(stderr, "usage: fork PROG_TO_EXEC\n");
31 exit(1);
32 }
33
34 printf("Fork test program, parent pid is %d\n", getpid());
35 trace_mark(ust, before_fork, MARK_NOARGS);
36
37 result = fork();
38 if(result == -1) {
39 perror("fork");
40 return 1;
41 }
42 if(result == 0) {
43 char *args[] = {"fork2", NULL};
44
45 printf("Child pid is %d\n", getpid());
46
47 trace_mark(ust, after_fork_child, MARK_NOARGS);
48
49 trace_mark(ust, before_exec, "pid %d", getpid());
50
51 result = execve(argv[1], args, env);
52 if(result == -1) {
53 perror("execve");
54 return 1;
55 }
56
57 trace_mark(ust, after_exec, "pid %d", getpid());
58 }
59 else {
60 trace_mark(ust, after_fork_parent, MARK_NOARGS);
61 }
62
63 return 0;
64 }
This page took 0.029889 seconds and 4 git commands to generate.