Everyone:
For the past couple of weeks, we have studied how an operating system virtualizes the CPU by providing processes and scheduling policies. By enabling users to execute multiple jobs simultaneously, the OS enables better utilization of the hardware and allows for more sophisticated workflows. Unfortunately, this multiprogramming ability comes with the cost of complexity due to issues related to concurrency.
This week we will examine both event-based programming and pthreads. Afterwards, we will further explore how to tackle the challenges of concurrency with tools such as locks, condition variables, and semaphores.
For this reading assignment, you are to read about two forms of concurrency: event-based programming via select and poll, and threads ala pthreads, submit your responses to the Reading 04 Quiz, and explore system calls with strace.
The readings for this week are:
Once you have done the readings, answer the following Reading 04 Quiz questions:
For this week, you are to explore system calls by running strace on
your program
from Reading 03:
$ cd reading03 # Go to reading03 folder
$ strace -c ./program * # Trace the system calls used by the Reading 03 program
After running strace a few times, you are to modify program.c
in
reading04
to print the responses to the following questions:
Order the following system calls from fastest to slowest: open
,
close
, read
. (Print response with only a single space between each
word)
Considering open
, close
, and read
, which system call is called the most?
Considering open
, close
, and read
, which system call failed the most?
Instead of fork, which system call was used to create a new process?
Considering open
and clone
, which system call was the slowest (ie.
most usecs/call
)?
Considering close
, stat
, and wait4
, which system call was the
slowest (ie. most seconds
)?
Note: We will consider openat
to be equivalent to open
when
examining the strace output.
Note: Subsequent runs of your program may access the filesystem cache and thus have different times from your first invocation. Use the times from the initial (that is, non-cached) run.
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 reading04 # Create reading04 branch and check it out
$ cd reading04 # Go into reading04 folder
$ $EDITOR answers.json # Edit your answers.json file
$ ../.scripts/check.py # Check reading04 quiz
Checking reading04 quiz ...
Q1 0.20
Q2 0.20
Q3 0.30
Q4 1.10
Q5 0.10
Q6 0.20
Q7 0.40
Q8 0.50
Score 3.00 / 3.00
Status Success
$ git add answers.json # Add answers.json to staging area
$ git commit -m "Reading 04: Quiz" # Commit work
$ $EDITOR program.c # Edit your program.c file
$ make test-program # Check reading04 program
Testing reading04 program...
Score 3.00 / 3.00
Status Success
$ git add program.c # Add program.c to staging area
$ git add Makefile # Add Makefile to staging area
$ git commit -m "Reading 04: Code" # Commit work
$ git push -u origin reading04 # Push branch to GitHub
Once you have committed your work and pushed it to GitHub, remember to create a pull request and assign it to the appropriate teaching assistant from the Reading 04 TA List.