Earn Higher Grades With Instant Assignment Help.Ask Question!

Operating System
(5/5)

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,

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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-sitterapp-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

 

Attachments:
(5/5)

Related Questions

Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
923 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
931 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
556 Answers Hire Me