A system runs several processes simultaneously. Sometimes it becomes necessary to pass a notification to a process alerting it of an event. A user or the system uses a signal to pass that notification to the process. A signal contains a signal number and is used to control processes. There are a number of signals available for use but most of the time you deal with only a few of them. Each signal is associated with a unique number, a name, and an action. A list of the available signals can be displayed with the kill command using the -l option:
The commands used to pass a signal to a process are kill and pkill. These commands are usually used to terminate a process. Ordinary users can kill processes they own, while the root user can kill any process.
The syntax of the kill command to kill a process is:
# kill PID # kill -s <signal name or number> PID
Specify multiple PIDs if you wish to kill all of them in one go.
The syntax of the pkill command to kill a process is:
# pkill process_name # pkill -s <signal name or number> process_name
Specify multiple process names if you wish to kill all of them in one go.
Let us look at a few examples for a better understanding.
To pass the soft terminate signal to the Cron daemon crond, use one of the following to determine its PID:
nextstep4it@localhost:~$ ps -ef | grep crond nextste+ 10309 9997 0 11:52 pts/1 00:00:00 grep --color=auto crond