CS318 - Pintos
Pintos source browser for JHU CS318 course
child-close.c
Go to the documentation of this file.
1 /** Child process run by multi-child-fd test.
2 
3  Attempts to close the file descriptor passed as the first
4  command-line argument. This is invalid, because file
5  descriptors are not inherited in Pintos. Two results are
6  allowed: either the system call should return without taking
7  any action, or the kernel should terminate the process with a
8  -1 exit code. */
9 
10 #include <ctype.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <syscall.h>
14 #include "tests/lib.h"
15 
16 const char *test_name = "child-close";
17 
18 int
19 main (int argc UNUSED, char *argv[])
20 {
21  msg ("begin");
22  if (!isdigit (*argv[1]))
23  fail ("bad command-line arguments");
24  close (atoi (argv[1]));
25  msg ("end");
26 
27  return 0;
28 }
lib.h
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
main
int main(int argc UNUSED, char *argv[])
Definition: child-close.c:19
test_name
const char * test_name
Child process run by multi-child-fd test.
Definition: child-close.c:16
ctype.h
fail
void fail(const char *format,...)
Definition: lib.c:40
close
void close(int fd)
Definition: syscall.c:139
msg
void msg(const char *format,...)
Definition: lib.c:28
stdlib.h
isdigit
static int isdigit(int c)
Definition: ctype.h:7