Ancient CS 61 Content Warning!!!!!1!!!
This is not the current version of the class.
This site was automatically translated from a wiki. The translation may have introduced mistakes (and the content might have been wrong to begin with).

11/15: Advanced waiting

One of our goals for this unit is that you be comfortable with new system calls, as well as the system calls we’ve explicitly taught. To that end, this exercise asks you to solve the “waitlimit” problem from class using advanced system calls you learn from manual pages and Internet resources. Your handout code is in cs61-exercises/shell4x.

Solution 1: signalfd

The signalfd system call implements “synchronous” signal delivery. It essentially implements a signal pipe entirely inside the kernel, reducing the number of system calls required to receive a signal. Read the manual page for signalfd (and browse the Internet for interesting links), then change waitlimit-signalfd.c to solve the waitlimit problem using signalfd instead of a signal pipe.

Solution 2: Signal blocking

The kernel allows processes to block most signals so they aren’t delivered immediately. (This is analogous to disabling interrupts in the kernel.) The relevant system calls include sigprocmask and pselect, and they use library calls such as sigemptyset and sigaddset to manipulate blocked-signal masks. It is possible to use signal blocking and pselect to solve the waitlimit problem without a signal pipe. Change waitlimit-pselect.c to do this.

This is a little harder than signalfd, so make sure you look online for resources. For instance: An article on pselect

When you're done

Please complete this survey.