PKUOS - Pintos
Pintos source browser for PKU Operating System course
recursor.c
Go to the documentation of this file.
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}
static struct intq buffer
Stores keys from the keyboard and serial port.
Definition: input.c:7
static void wait(struct intq *q, struct thread **waiter)
int snprintf(char *buffer, size_t buf_size, const char *format,...)
Like printf(), except that output is stored into BUFFER, which must have space for BUF_SIZE character...
Definition: stdio.c:62
int printf(const char *format,...)
Writes formatted output to the console.
Definition: stdio.c:79
int atoi(const char *s)
Converts a string representation of a signed decimal integer in S into an ‘int’, which is returned.
Definition: stdlib.c:10
void exit(int status)
Definition: syscall.c:72
pid_t exec(const char *file)
Definition: syscall.c:79
int pid_t
Process identifier.
Definition: syscall.h:8
int main(int argc, char *argv[])
Definition: recursor.c:6