Signals are used to send some information to a process or to handle an exception. Signals are sent to processes using the kill command explicitly. Some signals are bound to keyboard key combinations and are sent to the processes that are currently attached to the terminal. Every signal has a signal name and a number associated with it. All signals have default responses. Some signals are ignored by default. A list of signals and their default responses is shown in Table 20-2.
Signal Name | Signal Number | Description |
---|---|---|
SIGNULL | Check access to PID | |
SIGHUP | 1 | Hangup |
SIGINT | 2 | Interrupt |
SIGQUIT | 3 | Quit |
SIGILL | 4 | Illegal instruction (not reset when caught) |
SIGTRAP | 5 | Trace trap (not reset when caught) |
SIGABRT | 6 | Process abort signal |
SIGIOT | SIGABRT | IOT instruction |
SIGEMT | 7 | EMT instruction |
SIGFPE | 8 | Floating point exception |
SIGKILL | 9 | Kill (cannot be caught or ignored) |
SIGBUS | 10 | Bus error |
SIGSEGV | 11 | Segmentation violation |
SIGSYS | 12 | Bad argument to system call |
SIGPIPE | 13 | Write on a pipe with no one to read it |
SIGALRM | 14 | Alarm clock |
SIGTERM | 15 | Software termination signal from the kill; the default signal sent when using the kill command |
SIGUSR1 | 16 | User -defined signal 1 |
SIGUSR2 | 17 | User-defined signal 2 |
SIGCHLD | 18 | Child process terminated or stopped |
SIGCLD | SIGCHLD | Death of a child |
SIGPWR | 19 | Power state indication |
SIGVTALRM | 20 | Virtual timer alarm |
SIGPROF | 21 | Profiling timer alarm |
SIGIO | 22 | Asynchronous I/O |
SIGPOLL | SIGIO | For HP-UX hpstreams signal |
SIGWINCH | 23 | Window size change signal |
SIGWINDOW | SIGWINCH | Added for compatibility reasons |
SIGSTOP | 24 | Stop signal (cannot be caught or ignored) |
SIGTSTP | 25 | Interactive stop signal |
SIGCONT | 26 | Continue if stopped |
SIGTTIN | 27 | Read from the control terminal attempted by a member of a background process group |
SIGTTOU | 28 | Write to the control terminal attempted by a member of a background process group |
SIGURG | 29 | Urgent condition on the I/O channel |
SIGLOST | 30 | Remote lock lost (NFS) |
SIGRESERVE | 31 | Save for future use |
SIGDIL | 32 | DIL signal |
SIGXCPU | 33 | CPU time limit exceeded ( setrlimit ) |
SIGXFSZ | 34 | CPU file size limit exceeded ( setrlimit ) |
SIGCANCEL | 35 | Used for pthread cancelation |
SIGGFAULT | 36 | Graphics framebuffer fault |
SIGRTMIN | 37 | First (highest priority) realtime signal |
SIGRTMAX | 44 | Last ( lowest priority) realtime signal |
The kill command is used to send a signal to a process. If no signal is specified on the command line, it sends SIGTERM (signal 15 ) to the process specified. The general syntax of the kill command is:
kill [-signal] process
To send a SIGTERM signal to a process having process an ID of 1556, use one of the following commands; all of these are equivalent.
kill -SIGTERM 1556 kill -15 1556 kill 1556 kill -s SIGTERM 1556 kill -s 15 1556
The SIGTERM signal is used to terminate a process gracefully if it doesn't have a disabled signal. If a process ignores this signal, you can send a SIGKILL (signal 9 ) signal to terminate it. This signal can't be ignored and it forces a process to terminate. The following command terminates a process having a process ID of 1556 .
kill -9 1556
However, it must be noted that a signal is not received by a process that hangs in an I/O operation and it therefore never gets scheduled after that. So it may happen that you are sending a SIGKILL to a process and it does not terminate. The kill -l command lists available signals and their respective numbers as shown here.
# kill -l 1) HUP 23) WINCH 2) INT 24) STOP 3) QUIT 25) TSTP 4) ILL 26) CONT 5) TRAP 27) TTIN 6) ABRT 28) TTOU 7) EMT 29) URG 8) FPE 30) LOST 9) KILL 31) RESERVED 10) BUS 32) DIL 11) SEGV 33) XCPU 12) SYS 34) XFSZ 13) PIPE 35) The specified trap syntax is not correct. 14) ALRM 36) The specified trap syntax is not correct. 15) TERM 37) RTMIN 16) USR1 38) RTMIN+1 17) USR2 39) RTMIN+2 18) CHLD 40) RTMIN+3 19) PWR 41) RTMAX-3 20) VTALRM 42) RTMAX-2 21) PROF 43) RTMAX-1 22) IO 44) RTMAX
The nohup command executes another command with the hangup and quit signals ignored. Usually a process is attached to a terminal (TTY) or a pseudoterminal (pty). If the user logs out from that terminal, the process also terminates. The nohup command stops process termination in such a case. Unless the screen output is redirected, the screen output of the executing program is stored in the nohup.out file. If a program takes a long time, such as a batch program, you may start it using the nohup command and then log out. The following command line runs a shell program myprog with the help of the nohup command.
nohup myprog &
The nohup command applies to all lines in the shell script. If you are using more than one command with nohup on the command line, these can be grouped as follows .
nohup (prog1 ; prog2)
Signals can also be sent to a processes using the SAM Process Control area as shown in Figure 20-1. Just select a process and use the Actions menu to kill it or change its priority, as discussed in the next section.
Top |