From cab681366d2cf9039b3cfb8b8ce97ddaf6b5ba53 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Tue, 13 Oct 2009 19:12:45 -0400 Subject: [PATCH] tests/fork: updates --- tests/fork/fork.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tests/fork/fork.c b/tests/fork/fork.c index 20a0877..677261b 100644 --- a/tests/fork/fork.c +++ b/tests/fork/fork.c @@ -1,17 +1,21 @@ #include #include +#include #include "marker.h" -int main() +int main(int argc, char **argv, char *env[]) { int result; - printf("Fork test program\n"); - trace_mark(ust, before_fork, MARK_NOARGS); + if(argc < 2 ) { + fprintf(stderr, "usage: fork PROG_TO_EXEC\n"); + exit(1); + } - sleep(5); + printf("Fork test program, parent pid is %d\n", getpid()); + trace_mark(ust, before_fork, MARK_NOARGS); result = fork(); if(result == -1) { @@ -19,7 +23,21 @@ int main() return 1; } if(result == 0) { + char *args[] = {"fork2", NULL}; + + printf("Child pid is %d\n", getpid()); + trace_mark(ust, after_fork_child, MARK_NOARGS); + + trace_mark(ust, before_exec, "pid %d", getpid()); + + result = execve(argv[1], args, env); + if(result == -1) { + perror("execve"); + return 1; + } + + trace_mark(ust, after_exec, "pid %d", getpid()); } else { trace_mark(ust, after_fork_parent, MARK_NOARGS); -- 2.34.1