PKUOS - Pintos
Pintos source browser for PKU Operating System course
multi-recurse.c
Go to the documentation of this file.
1/** Executes itself recursively to the depth indicated by the
2 first command-line argument. */
3
4#include <debug.h>
5#include <stdlib.h>
6#include <stdio.h>
7#include <syscall.h>
8#include "tests/lib.h"
9
10const char *test_name = "multi-recurse";
11
12int
13main (int argc UNUSED, char *argv[])
14{
15 int n = atoi (argv[1]);
16
17 msg ("begin %d", n);
18 if (n != 0)
19 {
20 char child_cmd[128];
21 pid_t child_pid;
22 int code;
23
24 snprintf (child_cmd, sizeof child_cmd, "multi-recurse %d", n - 1);
25 CHECK ((child_pid = exec (child_cmd)) != -1, "exec(\"%s\")", child_cmd);
26
27 code = wait (child_pid);
28 if (code != n - 1)
29 fail ("wait(exec(\"%s\")) returned %d", child_cmd, code);
30 }
31
32 msg ("end %d", n);
33 return n;
34}
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
Definition: debug.h: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 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
pid_t exec(const char *file)
Definition: syscall.c:79
int pid_t
Process identifier.
Definition: syscall.h:8
void fail(const char *format,...)
Definition: lib.c:40
void msg(const char *format,...)
Definition: lib.c:28
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
int main(int argc UNUSED, char *argv[])
Definition: multi-recurse.c:13
const char * test_name
Executes itself recursively to the depth indicated by the first command-line argument.
Definition: multi-recurse.c:10