Discovering System Processes Part II
11/22/2000In last week's article, we took a look at what processes are and how to view the running processes on your FreeBSD system. In this week's article, I'd like to look at how processes talk to each other, how you can talk to your processes, and why you might want to do so.
When processes talk to each other, it is called interprocess communication. Processes aren't allowed to say just anything to each other; instead, your FreeBSD system comes with 31 possible predefined messages. These messages are called signals; you can view these signals with this command:
kill -l
HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH INFO USR1 USR2
Each signal has a numerical equivalent, and the signals are listed in numerical order; therefore, HUP=1, INT=2, etc. Processes are allowed to send these signals to each other; users are also allowed to send these signals to processes.
To find out what each of these signals does, read sigaction(2) by typing man 2 sigaction or signal(3) by typing man 3 signal. The following chart summarizes each of the 31 signals, their resultant actions, and a brief description of each. Although users can send any of these signals, I've included an asterisk next to the signals most commonly used by users.
Signal Name |
# |
Default Action |
Description |
* |
1 |
terminate process |
terminal line hangup |
* |
2 |
terminate process |
interrupt program |
* |
3 |
create core image |
quit program |
|
4 |
create core image |
illegal instruction |
|
5 |
create core image |
trace trap |
|
6 |
create core image |
abort(3) call |
|
7 |
create core image |
emulate instruction executed |
|
8 |
create core image |
floating-point exception |
* |
9 |
terminate process |
kill program |
|
10 |
create core image |
bus error |
|
11 |
create core image |
segmentation violation |
|
12 |
create core image |
non-existent system call |
|
13 |
terminate process |
write on a pipe with no reader |
|
14 |
terminate process |
real-time timer expired |
* |
15 |
terminate process |
software termination signal |
|
16 |
discard signal |
urgent condition |
* |
17 |
stop process |
stop (cannot be ignored) |
* |
18 |
stop process |
stop keyboard signal |
|
19 |
discard signal |
continue after stop |
|
20 |
discard signal |
child status has changed |
|
21 |
stop process |
background read attempted |
|
22 |
stop process |
background write attempted |
|
23 |
discard signal |
I/O is possible |
|
24 |
terminate process |
CPU time limit exceeded |
|
25 |
terminate process |
file size limit exceeded |
|
26 |
terminate process |
virtual time alarm |
|
27 |
terminate process |
profiling timer alarm |
|
28 |
discard signal |
Window size change |
|
29 |
discard signal |
status request from keyboard |
|
30 |
terminate process |
User defined signal 1 |
|
31 |
terminate process |
User defined signal 2 |
Some signals are used so often by users that they have been mapped to control characters. To view your control character mappings, look at the last four lines of the output of:
stty -e
discard dsusp eof eol eol2 erase intr kill lnext ^O ^Y ^D <undef> <undef> ^H ^C ^U ^V min quit reprint start status stop susp time werase 1 ^\ ^R ^Q ^T ^S ^Z 0 ^W
The ^ symbol means to press your CTRL key at the same time as the letter that follows it. Note that three signals have been mapped as control characters:
- ^C has been mapped to the
INTsignal, or signal 2 - ^\ has been mapped to the
QUITsignal, or signal 3 - ^Z has been mapped to the
TSTPsignal, or signal 18 (even though it's calledsusphere)
Don't confuse the word kill in this output with the KILL signal (signal 9). ^U will erase an entire line, not send a signal 9. To prove this to yourself, type a long string of words at your prompt, then do a ^U.
So, how do you send signals that haven't been mapped to control characters? Use the kill command.
whatis kill
kill(1) - terminate or signal a process
kill(2) - send signal to a process
There's a couple of different ways to use kill; if you simply type:
kill PID
the default TERM signal will be sent to the process with the PID that you indicated. If you wish to change the type of signal to send, you can specify the signal either by its name or by its number like so:
kill -signal_name PID
or
kill -signal_number PID
So:
kill PID
kill -TERM PID
and
kill -15 PID
are equivalent commands. Remember that Unix is case-sensitive; if you type:
kill -term PID
you'll receive the following error message:
term: Unknown signal; kill -l lists all signals.
So, now that we've seen the 31 possible messages and how to send them, let's look at examples of reasons you would want to send a signal to a process. Often when you're working your way through the FreeBSD handbook or a tutorial, you'll learn how to make changes to a configuration file and will then be prompted to send a HUP signal. Most processes only read their configuration file when they first start up; the HUP signal tells a process to stop running; when that process restarts, it will reread its configuration file and your changes to that file will take effect. Also, every time you log out of a terminal, a HUP signal is sent to all processes running on that terminal; this means that all processes that were running on that terminal will be stopped.
Pages: 1, 2 |