next up previous
Next: 2.9 Open Compatibility Up: 2. Environmentally Friendly I/O Previous: 2.7 User and Group Identities

  
2.8 Processes and Process Groups

An open pump stream is always connected to a child process, whose process id (see Section 2.17.2 [Processes]) can be retrieved by the integer-valued expression *

pid (fd)
If fd is omitted, pid just returns the process id of the calling process, like the Unix getpid routine.

The existence of a process can be interrogated by the expression *

pexists id
which tests whether id is the process id of a process currently known to the host operating system. This will be true even if the referred-to process has already exited but not had its status ``reaped'' yet by some equivalent of wait (again, see Section 2.17.2 [Processes]).

Finally, to send a signal to any existing process, a SETL program can execute the built-in *

kill (idsignal_name);
If signal_name is omitted, it defaults to `TERM'. As with signal names passed to open, alphabetic case is not significant, and the prefix `SIG' is optional. Kill also allows an integer-valued signal number to be used in place of a signal name. If id is positive, it is taken as a process id, but if it is less than -1, its absolute value is taken as a process group id (see the description of getpgrp below), and the signal is sent to all members of that process group. An id of 0 is equivalent to -getpgrp, i.e., all members of the caller's process group. An id of -1 causes the signal to be sent to all processes to which the caller has permission to send signals. For user-level (non-superuser) processes, -1 therefore stands for all processes owned by the user associated with the calling process (see getuid in Section 2.7 [User and Group Identities]).

Most signals cause process termination, sometimes with other side-effects such as creating a file core (an image of the final virtual memory state of the process). As described in Section 2.4.1 [Signals], the recipient may also have altered its default signal-handling behavior. One signal, `KILL', is designed to be impossible to trap in this way, providing a method of last resort to arrest otherwise uninterruptible processes.

A full discussion of the semantics of signals is outside the scope of this dissertation, but the Unix 98 documentation [154] on the sigaction function and on the <signal.h> C header file gives more details.

In Unix, each new process belongs initially to the process group of its parent. The value of *

getpgrp              -- trailing ``()'' optional, as usual
is the process group id, an integer. The call *
setpgrp;
sets the process group id equal to the process id. If this is the first time the process has called setpgrp, it establishes a new process group, of which the calling process is the leader.

The main significance of process groups is in the distribution of signals. If the first argument to the kill routine described in Section 2.8 [Processes and Process Groups] is less than -1, its absolute value is taken to be a process group id, and the signal passed to kill is sent to all processes in that process group. This can be convenient for taking down whole trees of processes at once, though in practice, more orderly shutdowns are often attempted first.


next up previous
Next: 2.9 Open Compatibility Up: 2. Environmentally Friendly I/O Previous: 2.7 User and Group Identities
David Bacon
1999-12-10