Читать книгу Linux Bible - Christopher Negus - Страница 188
Using kill to signal processes by PID
ОглавлениеUsing commands such as ps
and top
, you can find processes to which you want to send a signal. Then you can use the process ID of that process as an option to the kill
command, along with the signal you want to send.
TABLE 6.1 Signals Available in Linux
Signal | Number | Description |
SIGHUP | 1 | Hang-up detected on controlling terminal or death of controlling process. |
SIGINT | 2 | Interrupt from keyboard. |
SIGQUIT | 3 | Quit from keyboard. |
SIGABRT | 6 | Abort signal from abort(3). |
SIGKILL | 9 | Kill signal. |
SIGTERM | 15 | Termination signal. |
SIGCONT | 19 ,18 ,25 | Continue if stopped. |
SIGSTOP | 17 ,19 ,23 | Stop process. |
For example, you run the top
command and see that the bigcommand
process is consuming most of your processing power:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 10432 chris 20 0 471m 121m 18m S 99.9 3.2 77:01.76 bigcommand
Here, the bigcommand
process is consuming 99.9 percent of the CPU. You decide that you want to kill it so that other processes have a shot at the CPU. If you use the process ID of the running bigcommand
process, here are some examples of the kill
command that you can use to kill that process:
$ kill 10432 $ kill -15 10432 $ kill -SIGKILL 10432
The default signal sent by kill is 15
(SIGTERM
), so the first two examples have exactly the same results. On occasion, a SIGTERM
doesn't kill a process, so you may need a SIGKILL
to kill it. Instead of SIGKILL
, you can use –9
to get the same result.
Another useful signal is SIGHUP
. If, for example, something on your GNOME desktop were corrupted, you could send the gnome-shell
a SIGHUP
signal to reread its configuration files and restart the desktop. If the process ID for gnome-shell
were 1833, here are two ways you could send it a SIGHUP
signal:
# kill -1 1833 # killall -HUP gnome-shell