summaryrefslogtreecommitdiffstats
path: root/examples/recursor.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/recursor.c')
-rw-r--r--examples/recursor.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/recursor.c b/examples/recursor.c
new file mode 100644
index 0000000..79c784a
--- /dev/null
+++ b/examples/recursor.c
@@ -0,0 +1,34 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <syscall.h>
4
5int
6main (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}