The kill command in Linux is used to terminate a currently running process. There are processes that exceed their run-time limit or get stuck and become unresponsive. The kill command is used to suspend (or
stop) such processes. The kill command sends a signal to the process which it wants to terminate. Depending upon what the user wants, different signals can be sent. The default signal that is sent by the kill command is TERM. The kill command enables the user to restart a process without restarting the whole machine.
The syntax of the kill command is -
If the <pid> equals 0, then the signal is sent to all the processes which are in the same process group as the calling process. If the <pid> is -1, then the signal is sent to each process for which the calling process has permission to send signals to. If the <pid> is less than -1, then the signal is sent to each process in the process group whose <pid> is equal to -pid.
The return type of the command depends upon whether it was a success or a failure. On success (i.e when at least one of the intended signals was sent), a 0 is returned. In case of a failure, 1 is returned and the errorno (error number) is set appropriately and 64 is returned when the kill command has partial success (when there are multiple target processes).
The errors that can occur are as follows -
1. EINVAL: An invalid signal was specified along with the command.
2. EPERM: The calling process does not have the appropriate permissions to send signals to any of the target processes.
3. ESRCH: The target process (or the target process group) does not exist or has terminated even before the signal has reached it.
There are many options that are used with the kill command. A few of them are -
1. kill -l - The -l option is used to view the various signals that can be sent along with the kill command.
2. kill -s or kill --signal - The -s (or --signal) option is used to send a different signal (other than TERM)
along with the kill command.
Here, the [signal] part is used to send the desired signal and as seen above, the different signal options can be viewed using the -l option.
3. kill -L or kill -table - This option is similar to the -l option but it prints all the signals along with their corresponding numbers.
4. kill -p or kill --pid - It does not send the signal to the named process. It just returns the <pid> for that process.
5. kill --timeout - The --timeout option makes the kill command wait for a certain amount of time (in milliseconds) before sending the signal mentioned by the kill command.
6. kill --verbose - This option prints all the pid(s) of all the target processes along with the signal that will be sent to them.
|Usermod command in Linux||4511||1|
|SSH Command In Linux||788||7|
|Introduction to Named Pipes||1058||3|
|Linux KILL Command||2783||5|
|Soft Link and Hard Link In Linux||421||2|
|Vi Editor in Linux||594||6|
|FDisk Command in Linux||540||5|
|How to view the History in Linux||448||2|
|Process Manipulation in Linux||1614||4|
|Export command in Linux||411||1|
|ID command in Linux||413||1|
|Netstat Command in Linux||624||3|
|Chmod Command in Linux||437||1|
|Compressing Files in Linux||354||1|
|Crontab in Linux||477||1|
|File Manipulation in Linux||615||5|
|Curl Command in Linux||505||1|
|Env Command in Linux||398||5|
|LSOF Command in Linux||406||1|
|User Manual in Linux||433||1|
|Whereis command in Linux||436||1|
|4 Lesser Known Commands in Linux||468||6|
|Shell Scripting in Linux||631||4|
|Alias command in Linux||373||1|
|How to Kill a Process using Command Line||471||3|