diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /examples/recursor.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'examples/recursor.c')
| -rw-r--r-- | examples/recursor.c | 34 |
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 | |||
| 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 | } | ||
