BSD DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


FreeBSD Basics

Discovering System Processes Part II

11/22/2000

In 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

*HUP

1

terminate process

terminal line hangup

*INT

2

terminate process

interrupt program

*QUIT

3

create core image

quit program

ILL

4

create core image

illegal instruction

TRAP

5

create core image

trace trap

ABRT

6

create core image

abort(3) call

EMT

7

create core image

emulate instruction executed

FPE

8

create core image

floating-point exception

*KILL

9

terminate process

kill program

BUS

10

create core image

bus error

SEGV

11

create core image

segmentation violation

SYS

12

create core image

non-existent system call

PIPE

13

terminate process

write on a pipe with no reader

ALRM

14

terminate process

real-time timer expired

*TERM

15

terminate process

software termination signal

URG

16

discard signal

urgent condition

*STOP

17

stop process

stop (cannot be ignored)

*TSTP

18

stop process

stop keyboard signal

CONT

19

discard signal

continue after stop

CHLD

20

discard signal

child status has changed

TTIN

21

stop process

background read attempted

TTOU

22

stop process

background write attempted

IO

23

discard signal

I/O is possible

XCPU

24

terminate process

CPU time limit exceeded

XFSZ

25

terminate process

file size limit exceeded

VTALRM

26

terminate process

virtual time alarm

PROF

27

terminate process

profiling timer alarm

WINCH

28

discard signal

Window size change

INFO

29

discard signal

status request from keyboard

USR1

30

terminate process

User defined signal 1

USR2

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 INT signal, or signal 2
  • ^\ has been mapped to the QUIT signal, or signal 3
  • ^Z has been mapped to the TSTP signal, or signal 18 (even though it's called susp here)

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

Next Pagearrow





Sponsored by: