aboutsummaryrefslogtreecommitdiffstats
path: root/src/examples/recursor.c
diff options
context:
space:
mode:
authorklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
committerklaar36 <klas.arvidsson@liu.se>2015-03-20 17:30:24 +0100
commite7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad (patch)
tree4de97af7207676b69cb6a9aba8cb443cc134855d /src/examples/recursor.c
parentb0418a24e709f0632d2ede5b0f327c422931939b (diff)
downloadpintos-rs-e7bc50ca8ffcaa6ed68ebd2315f78b0f5a7d10ad.tar.gz
Initial Pintos
Diffstat (limited to 'src/examples/recursor.c')
-rw-r--r--src/examples/recursor.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/examples/recursor.c b/src/examples/recursor.c
new file mode 100644
index 0000000..79c784a
--- /dev/null
+++ b/src/examples/recursor.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <syscall.h>
+
+int
+main (int argc, char *argv[])
+{
+ char buffer[128];
+ pid_t pid;
+ int retval = 0;
+
+ if (argc != 4)
+ {
+ printf ("usage: recursor <string> <depth> <waitp>\n");
+ exit (1);
+ }
+
+ /* Print args. */
+ printf ("%s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
+
+ /* Execute child and wait for it to finish if requested. */
+ if (atoi (argv[2]) != 0)
+ {
+ snprintf (buffer, sizeof buffer,
+ "recursor %s %d %s", argv[1], atoi (argv[2]) - 1, argv[3]);
+ pid = exec (buffer);
+ if (atoi (argv[3]))
+ retval = wait (pid);
+ }
+
+ /* Done. */
+ printf ("%s %s: dying, retval=%d\n", argv[1], argv[2], retval);
+ exit (retval);
+}