Kill or terminate a process in Linux

Kill command is used to terminate a process in Linux. The kill command sends the specified signal such as kill process to the specified process. If no signal is specified, the SIGTERM signal is sent.

Syntax:
kill [signal] PID

A list of common signals:

SIGHUP-(1)Hangup detected on controlling terminal or death of controlling process. Use SIGHUP to reload configuration files and open/close log files
SIGKILL-(9)Kill signal. Use SIGKILL as a last resort to kill process. This will not save data or cleaning kill the process
SIGTERM-(15)Termination signal. This is the default and safest way to kill process

Example:
For example, we are terminating process java with a -15 signal, which will terminate the process safely.

Kill or terminate a process in Linux

Points to remember:

  • You can kill all your own processes.
  • The only root user can kill system-level processes.
  • The only root user can kill process started by other users.
To kill multiple processes in a single command, mention all PID’s in command:
kill -15 PID1 PID2 PID3
 
To kill the process with its name:
You can kill any process by specifying its full name or partial name. So there is no need for you to find out the PID of the process to send the signal.
pkill java
Further, you can also terminate a process in Linux with its name using killall command but with killall, you need to specify the full name of the process.
 
Note: There are many kill signals that each serve a particular purpose. Typing “kill -l” will list the kill signals. 
Kill or terminate a process in Linux
You may want to see
How to sort contents of a file

The sort command is used to sort the contents of a file. You can sort the data in a text Read more

How to use sed command in Linux

sed, short for "stream editor", allows you to filter and transform text. A stream editor is used to perform basic Read more

How to use crontab in Linux

Cron is the system process that will automatically perform tasks for you according to a set schedule. The schedule is Read more

How to extract archive file in Linux

To extract archive file in Linux, you can use the tar command, used for extracting content from the archive files. "tar" Read more

Leave a Reply

Your email address will not be published. Required fields are marked *