This Is Not The Course Website You Are Looking For

This course website is from a previous semester. If you are currently in the class, please make sure you are viewing the latest course website instead of this old one.

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 GitHub

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

$ cd reading13                        # Go into reading13 folder

# Download Makefile
$ curl -sLO https://raw.githubusercontent.com/nd-cse-20289-sp23/cse-20289-sp23-assignments/master/reading13/Makefile

# Download Starter code
$ curl -sLO https://raw.githubusercontent.com/nd-cse-20289-sp23/cse-20289-sp23-assignments/master/reading13/doit.c

# Download, build, and execute tests
$ make test

Questions

Record the answers to the following Reading 13 Quiz questions in your reading13 branch:

Programs

Given the provided Makefile and doit.c, you are to do the following:

  1. Modify Makefile to include a rule for the doit program. Be sure to use the CC and CFLAGS variables in your rule.

    Once you have a working Makefile, you should be able to use the make command to run your recipes:

    $ make clean                                # Remove targets
    rm -f doit
    
    $ make                                      # Build targets
    gcc -g -Wall -Werror -std=gnu99 -o doit doit.c
    
  2. Modify doit.c so that it uses system calls in C to implement your own version of the system function called doit.

    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 as shown below:

    $ make                # Build doit 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
    

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 GitHub

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

$ cd reading13                        # Go into reading13 folder

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

$ ../.scripts/check.py                # Check reading13 quiz
Checking reading13 quiz ...
      Q1 0.60
      Q2 0.40
   Score 1.00 / 1.00
  Status Success

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

$ $EDITOR doit.c                      # Edit source code

$ make test                           # Build and Run tests
Checking reading13 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 / 3.00
  Status Success

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

$ git push -u origin reading13        # Push branch to GitHub

Pull Request

Remember to create a Pull Request and assign the appropriate TA from the Reading 13 TA List.

DO NOT MERGE your own Pull Request. The TAs use open Pull Requests to keep track of which assignments to grade. Closing them yourself will cause a delay in grading and confuse the TAs.