Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / examples / recursor.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <syscall.h>
4
5 int
6 main (int argc, char *argv[])
7 {
8   char buffer[128];
9   pid_t pid;
10   int retval = 0;
11
12   if (argc != 4) 
13     {
14       printf ("usage: recursor <string> <depth> <waitp>\n");
15       exit (1);
16     }
17
18   /* Print args. */
19   printf ("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
20
21   /* Execute child and wait for it to finish if requested. */
22   if (atoi (argv[2]) != 0) 
23     {
24       snprintf (buffer, sizeof buffer,
25                 "recursor %s %d %s", argv[1], atoi (argv[2]) - 1, argv[3]);
26       pid = exec (buffer);
27       if (atoi (argv[3]))
28         retval = wait (pid);
29     }
30   
31   /* Done. */
32   printf ("%s %s: dying, retval=%d\n", argv[1], argv[2], retval);
33   exit (retval);
34 }