4a8c89fae509f67ab2b4693c6e9ffa951375299c
[pintos-anon] / grading / userprog / multi-parent-fd.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <syscall.h>
4 #include "sample.inc"
5
6 char actual[sizeof sample];
7
8 int
9 main (void) 
10 {
11   char child_cmd[128];
12   int byte_cnt;
13   int handle;
14
15   printf ("(multi-child-fd) begin\n");
16
17   handle = open("sample.txt");
18   if (handle < 2)
19     printf ("(multi-child-fd) fail: open() returned %d\n", handle);
20
21   snprintf (child_cmd, sizeof child_cmd, "child-close %d", handle);
22   
23   printf ("(multi-child-fd) join(exec()) = %d\n", join (exec (child_cmd)));
24
25   byte_cnt = read (handle, actual, sizeof actual - 1);
26   if (byte_cnt != sizeof actual - 1)
27     printf ("(multi-child-fd) fail: read() returned %d instead of %d\n",
28             byte_cnt, sizeof actual - 1);
29   else if (strcmp (sample, actual))
30     printf ("(multi-child-fd) fail: expected text differs from actual:\n%s",
31             actual);
32   
33   printf ("(multi-child-fd) end\n");
34   return 0;
35 }