Everyone:

Next week, we will discuss system calls involving processes and signals. We will discover the wonders of the fork bomb and examine how something like the TROLL from Homework 01 works.

TL;DR

The focus of this reading is to explore system calls related to processes and signals in C.

Readings

The readings for this week are:

  1. Operating Systems: Three Easy Pieces

Optional References

  1. System Programming Wiki

  2. Beej's Guide to Unix IPC

Quiz

This week, the reading is split into two sections: the first part is a dredd quiz, while the second part involves one C program: doit.c.

To test the C program, you will need to download the Makefile and test scripts:

$ git checkout master                 # Make sure we are in master branch
$ git pull --rebase                   # Make sure we are up-to-date with GitLab

$ git checkout -b reading11           # Create reading11 branch and check it out

$ cd reading11                        # Go into reading11 folder

# Download Makefile
$ curl -sLOk https://gitlab.com/nd-cse-20289-sp19/cse-20289-sp19-assignments/raw/master/reading11/Makefile

# Download Starter code
$ curl -sLOk https://gitlab.com/nd-cse-20289-sp19/cse-20289-sp19-assignments/raw/master/reading11/doit.c

# Download, build, and execute tests
$ make test

Questions

Record the answers to the following Reading 11 Quiz questions in your reading11 branch:

Programs

The C standard library provides a system function that can be used to execute another command as an external process. Internally, it uses fork, exec, and wait. For this assignment, you are to implement your own version of the system function called doit inside the doit.c starter code:

/**
 * Run specified program with the bourne shell.
 * @param     command     Command to run.
 * @return    Exit status of child process.
 */
int doit(const char *command);

This doit function forks a new process, execs the specified command, waits for the child process to complete, and then returns the exit status of the child process.

Once you have this doit function, you are to utilize it in the doit.c program such that it executes the first command-line argument specified by the user via the function you wrote.

Makefile

Update the Makefile such that it contains a rule that builds the doit program:

$ make                # Build walk program
gcc -g -Wall -Werror -std=gnu99 -o doit doit.c

$ ./doit              # Usage
Usage: ./doit COMMAND

$ ./doit ls           # Run doit program with ls
doit  doit.c  Makefile  README.md  test_doit.sh

$ make clean          # Cleanup
rm -f doit

Requirements

Your program must:

Submission

To submit you work, follow the same process outlined in Reading 01:

$ git checkout master                 # Make sure we are in master branch
$ git pull --rebase                   # Make sure we are up-to-date with GitLab

$ git checkout -b reading11           # Create reading11 branch and check it out

$ cd reading11                        # Go into reading11 folder

$ $EDITOR answers.json                # Edit your answers.json file

$ ../.scripts/submit.py               # Check reading11 quiz
Submitting reading11 assignment ...
Submitting reading11 quiz ...
      Q1 0.60
      Q2 0.40
   Score 1.00

$ git add answers.json                # Add answers.json to staging area
$ git commit -m "Reading 11: Quiz"    # Commit work

$ $EDITOR doit.c                      # Edit source code

$ make test                           # Build and Run tests
Testing doit ...
 doit (syscalls)                                              ... Success
 doit (usage)                                                 ... Success
 doit true (status)                                           ... Success
 doit true (valgrind)                                         ... Success
 doit false (status)                                          ... Success
 doit false (valgrind)                                        ... Success
 doit NOPE (status)                                           ... Success
 doit NOPE (valgrind)                                         ... Success
 doit ls (output)                                             ... Success
 doit ls (status)                                             ... Success
 doit ls (valgrind)                                           ... Success
 doit 'echo execution of all things' (output)                 ... Success
 doit 'echo execution of all things' (status)                 ... Success
 doit 'echo execution of all things' (valgrind)               ... Success
   Score 3.00

$ git add Makefile                    # Add Makefile to staging area
$ git add doit.c                      # Add source code to staging area
$ git commit -m "Reading 11: Code"    # Commit work

$ git push -u origin reading11        # Push branch to GitLab

Remember to create a merge request and assign the appropriate TA from the Reading 11 TA List.