Commit | Line | Data |
---|---|---|
a09dac63 PMF |
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 | ||
48c56fcf PMF |
18 | #include <stdio.h> |
19 | #include <unistd.h> | |
cab68136 | 20 | #include <sys/types.h> |
909bc43f | 21 | #include <stdlib.h> |
48c56fcf | 22 | |
93d0f2ea | 23 | #include <ust/marker.h> |
48c56fcf | 24 | |
cab68136 | 25 | int main(int argc, char **argv, char *env[]) |
48c56fcf PMF |
26 | { |
27 | int result; | |
28 | ||
cab68136 PMF |
29 | if(argc < 2 ) { |
30 | fprintf(stderr, "usage: fork PROG_TO_EXEC\n"); | |
31 | exit(1); | |
32 | } | |
48c56fcf | 33 | |
cab68136 PMF |
34 | printf("Fork test program, parent pid is %d\n", getpid()); |
35 | trace_mark(ust, before_fork, MARK_NOARGS); | |
48c56fcf PMF |
36 | |
37 | result = fork(); | |
38 | if(result == -1) { | |
39 | perror("fork"); | |
40 | return 1; | |
41 | } | |
42 | if(result == 0) { | |
cab68136 PMF |
43 | char *args[] = {"fork2", NULL}; |
44 | ||
45 | printf("Child pid is %d\n", getpid()); | |
46 | ||
48c56fcf | 47 | trace_mark(ust, after_fork_child, MARK_NOARGS); |
cab68136 PMF |
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()); | |
48c56fcf PMF |
58 | } |
59 | else { | |
60 | trace_mark(ust, after_fork_parent, MARK_NOARGS); | |
61 | } | |
62 | ||
63 | return 0; | |
64 | } |