tests/fork: updates
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 13 Oct 2009 23:12:45 +0000 (19:12 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Tue, 13 Oct 2009 23:12:45 +0000 (19:12 -0400)
tests/fork/fork.c

index 20a08779f367cc413d2da769c0b25853797f90ec..677261b17d7c7d03eb91d655f9052450307a42f7 100644 (file)
@@ -1,17 +1,21 @@
 #include <stdio.h>
 #include <unistd.h>
+#include <sys/types.h>
 
 #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);
This page took 0.023971 seconds and 4 git commands to generate.