CS318 - Pintos
Pintos source browser for JHU CS318 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 
10 const char *test_name = "multi-recurse";
11 
12 int
13 main (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 }
lib.h
snprintf
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
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
atoi
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
UNUSED
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
Definition: debug.h:7
exec
pid_t exec(const char *file)
Definition: syscall.c:79
fail
void fail(const char *format,...)
Definition: lib.c:40
main
int main(int argc UNUSED, char *argv[])
Definition: multi-recurse.c:13
wait
static void wait(struct intq *q, struct thread **waiter)
pid_t
int pid_t
Process identifier.
Definition: syscall.h:8
msg
void msg(const char *format,...)
Definition: lib.c:28
test_name
const char * test_name
Executes itself recursively to the depth indicated by the first command-line argument.
Definition: multi-recurse.c:10
stdlib.h
debug.h