Get your head around killing processes in Linux
Linux and Unix-like operating system come with the kill command to terminates stalled or unwanted processes without having to log out or restart the server.
The kill command sends the specified signal such as kill process to the specified process or process groups. If no signal is specified, the TERM signal is sent. Please note that kill command can be internal as part of modern shells built-in function or external located at /bin/kill. Usage and syntax remain similar regardless internal or external kill command.
A list of common Term signals
Linux and Unix-like operating system supports the standard terminate signals listed below:
- 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.
What is a PID?
A Linux or Unix process is running instance of a program. For example, Firefox is a running process if you are browsing the Internet. Each time you start Firefox browser, the system is automatically assigned a unique process identification number (PID). A PID is automatically assigned to each process when it is created on the system. To find out PID of firefox or httpd process use the following command:
pidof httpd pidof apache2 pidof firefox
OR use the combination of ps command and grep command:
ps aux | grep httpd ps aux | grep apache2 ps aux | grep firefox
kill command syntax
The syntax is:
kill [signal] PID kill -15 PID kill -9 PID kill -SIGTERM PID kill [options] -SIGTERM PID
Original link with full story below.