Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ jobs(3J) — AUX SR8.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

csh(1)

ioctl(2)

killpg(2)

setpgrp(2)

sigsys(2)

wait3(2)

signal(2)

JOBS(3J)

NAME

jobs − summary of job control facilities

SYNOPSIS

#include <sys/ioctl.h>
#include <signal.h>
#include <sys/vtimes.h>
#include <wait.h>

int fildes, signo;
short pid, pgrp;
union wait status;
struct vtimes vt;

setpgrp(pid, pgrp)
getpgrp(pid)
killpg(pgrp, signo)

sigset(signo, action)
sighold(signo)
sigrelse(signo)
sigpause(signo)
sigsys(signo, action)

wait3(&status, options, &vt)

DESCRIPTION

The facilities described here are used to support the job control implemented in csh(1), and may be used in other programs to provide similar facilities. Because these facilities are not standard in UNIX and because the signal mechanisms are also slightly different, the associated routines comprise what is known in Berkeley UNIX as the jobs library.

For descriptions of the individual routines see the various sections listed in SEE ALSO below.  This section attempt only to place these facilities in context, not to explain the semantics of the individual calls. 

Interrupt-level process handling. 

Using the mechanisms of sigset(3) it is possible to handle process state changes as they occur by providing an interrupt-handling routine for the SIGCHLD signal which occurs whenever the status of a child process changes.  A signal handler for this signal is established by:

sigset(SIGCHLD, onchild);

The shell or other process would then await a change in child status with code of the form:

recheck:
sighold(SIGCHLD);/* start critical section */
if (no children to process) {
sigpause(SIGCHLD);/* release SIGCHLD and pause */
goto recheck;
}
sigrelse(SIGCHLD);/* end critical region */
/* now have a child to process */

Here we are using sighold to temporarily block the SIGCHLD signal during the checking of the data structures telling us whether we have a child to process.  If we didn’t block the signal we would have a race condition since the signal might corrupt our decision by arriving shortly after we had finished checking the condition but before we paused. 

If we need to wait for something to happen, we call sigpause which automically releases the hold on the SIGCHLD signal and waits for a signal to occur by starting a pause(2). Otherwise we simply release the SIGCHLD signal and process the child. Sigpause is similar to the PDP-11 wait instruction, which returns the priority of the processor to the base level and idles waiting for an interrupt. 

It is important to note that the long-standing bug in the signal mechanism which would have lost a SIGCHLD signal which occurred while the signal was blocked has been fixed.  This is because sighold uses the SIG_HOLD signal set of sigsys(2) to prevent the signal action from being taken without losing the signal if it occurs.  Similarly, a signal action set with sigset has the signal held while the action routine is running, much as a the interrupt priority of the processor is raised when a device interrupt is taken. 

In this interrupt driven style of termination processing it is necessary that the wait calls used to retrieve status in the SIGCHLD signal handler not block.  This is because a single invocation of the SIGCHLD handler may indicate an arbitrary number of process status changes: signals are not queued.  This is similar to the case in a disk driver where several drives on a single controller may report status at once, while there is only one interrupt taken.  It is even possible for no children to be ready to report status when the SIGCHLD handler is invoked, if the signal was posted while the SIGCHLD handler was active, and the child was noticed due to a SIGCHLD initially sent for another process.  This causes no problem, since the handler will be called whenever there is work to do; the handler just has to collect all information by calling wait3 until it says no more information is available.  Further status changes are guaranteed to be reflected in another SIGCHLD handler call. 

Restarting system calls. 

In older versions of UNIX “slow” system calls were interrupted when signals occurred, returning EINTR.  The new signal mechanism sigset(3) normally restarts such calls rather than interrupting them. To summarize: pause and wait return error EINTR (as before), ioctl and wait3 restart, and read and write restart unless some data was read or written in which case they return indicating how much data was read or written.  In programs which use the older signal(2) mechanisms, all of these calls return EINTR if a signal occurs during the call.

SEE ALSO

csh(1), ioctl(2), killpg(2), setpgrp(2), sigsys(2), wait3(2), signal(2)

BUGS

The job control facilities are not available in standard version 7 UNIX.  These facilities are still under development and may change in future releases of the system as better inter-process communication facilities and support for virtual terminals become available.  The options and specifications of these system calls and even the calls themselves are thus subject to change. 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026