when linux starts up, it runs init. Nowadays this is a program called systemd. this program makes sure that things start up properly and stay running. if a process crashes systemd can detect this and start it back up.
we are going to write our own simple implementation of systemd that we will call app-sitter. app-sitter will take a list of programs to run (with the necessary arguments) from the command line. it will then start them up and babysit them: if a process stops running, it will start it back up again. since commands may take a variable number of arguments, we use a lone period ".". as a separator between commands. you can have extra periods and there need not be an ending period. for example, the following invocations will all produce the same result:
./app-sitter sleep 3 . wc app-sitter.c /etc/passwd
./app-sitter sleep 3 . . wc app-sitter.c /etc/passwd .
./app-sitter sleep 3 . wc app-sitter.c /etc/passwd . . .
of course, if a process dies right after it is started. the app-sitter should not try to restart it. so, if a process dies within 2 seconds after starting, app-sitter will not start it again and will print a message "spawning too fast" to the error file for the process. each time a process finishes, the message "exited rc = X" should be written to the error file of the process. X is the process exit code. if the process was killed with a signal "signal S" should be written to the error file. S is the signal number that killed the process. this information is gathered using the status parameter of the wait() system call. if the program cannot be started (exec fails), use perror("name of command") to get the error message and command name into the command's error file. processes that encounter an invalid command (exec fails) should have an exit code of 2.
app-sitter will also save all of the programs' stdout and stderr messages to files for later use. the filenames for these files start with a number indicating command number being run. in the previous example sleep was the first command, so it was command 0, and wc was command 1. the suffix of the filename will be .out for stdout and .err for stderr. use dup2() to make handle 1 (stdout) go to a file X.out and handle 2 (stderr) go to a file X.err.
here is an example run:
$ ./app-sitter sleep 3 . ls /frog ./ . wc app-sitter.c /etc/passwd . . .
app-sitter runs until there are no more processes running. in this example the ls and wc will not get restarted because they finish right after they are started. the sleep runs for 3 seconds, so app-sitter will keep restarting it, unless we do "pkill sleep" in another terminal. if we do pkill enough, app-sitter will decide that it is dying too fast and not restart it.
$ cat 0.out
$ cat 0.err
exited rc = 0
exited rc = 0
exited rc = 0
exited rc = 0
signal 15
exited rc = 0
signal 15
signal 15
spawning too fast
$ cat 1.out
./:
0.err
0.out
1.err
1.out
2.err
2.out
3.err
3.out
app-sitter
app-sitter.c
cmake-build-debug
CMakeLists.txt
main
$ cat 1.err
ls: cannot access '/frog': No such file or directory
exited rc = 2
spawning too fast
$ cat 2.out
109 304 2723 app-sitter.c
46 81 2645 /etc/passwd
155 385 5368 total
$ cat 2.err
exited rc = 0
spawning too fast
correctly uses fork() |
10 |
correctly uses wait() |
10 |
correctly uses dup2() |
10 |
a version of exec is used correctly |
10 |
the exit and signal codes and spawning too fast messages are printed correctly |
10 |
valgrind doesn't show any memory leaks |
10 |
dynamically sized data structures use malloc or calloc |
10 |
all processes run in parallel |
10 |
code compiles without errors or warnings -Wall |
10 |
zip file contains a single file called app-sitter.c |
10 |
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme