Process Control and Users
This lesson will introduce you to other system calls to manage and control processes.
We'll cover the following
Sending signals to a process
Beyond fork()
, exec()
, and wait()
, there are a lot of other interfaces for interacting with processes in UNIX systems. For example, the kill()
system call is used to send signals to a process, including directives to pause, die, and other useful imperatives. For convenience, in most UNIX shells, certain keystroke combinations are configured to deliver a specific signal to the currently running process; for example, control-c sends a SIGINT
(interrupt) to the process (normally terminating it) and control-z sends a SIGTSTP
(stop) signal thus pausing the process in mid-execution (you can resume it later with a command, e.g., the fg
built-in command found in many shells).
The entire signals subsystem provides a rich infrastructure to deliver external events to processes, including ways to receive and process those signals within individual processes, and ways to send signals to individual processes as well as entire process groups. To use this form of communication, a process should use the signal()
system call to “catch” various signals; doing so ensures that when a particular signal is delivered to a process, it will suspend its normal execution and run a particular piece of code in response to the signal.
Giving control of processes to users
This naturally raises the question: who can send a signal to a process, and who cannot? Generally, the systems we use can have multiple people using them at the same time; if one of these people can arbitrarily send signals such as SIGINT (to interrupt a process, likely terminating it), the usability and security of the system will be compromised. As a result, modern systems include a strong conception of the notion of a user. The user, after entering a password to establish credentials, logs in to gain access to system resources. The user may then launch one or many processes, and exercise full control over them (pause them, kill them, etc.). Users generally can only control their own processes; it is the job of the operating system to parcel out resources (such as CPU, memory, and disk) to each user (and their processes) to meet overall system goals.
ASIDE: RTFM — READ THE MAN PAGES
Many times in this course, when referring to a particular system call or library call, we’ll tell you to read the manual pages or man pages for short. Man pages are the original form of documentation that exist on UNIX systems; realize that they were created before the thing called the web existed.
Spending some time reading man pages is a key step in the growth of a systems programmer; there are tons of useful tidbits hidden in those pages. Some particularly useful pages to read are the man pages for whichever shell you are using (e.g., tcsh, or bash), and certainly for any system calls your program makes (in order to see what return values and error conditions exist).
Finally, reading the man pages can save you some embarrassment. When you ask colleagues about some intricacy of
fork()
, they may simply reply: “RTFM.” This is your colleagues’ way of gently urging you to Read The Man pages. The F in RTFM just adds a little color to the phrase…
Get hands-on with 1400+ tech skills courses.