Month: May 2017

Kill Process in Linux or Terminate a Process in UNIX / Linux Systems

Posted on

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:

  1. SIGHUP (1) – Hangup detected on controlling terminal or death of controlling process. Use SIGHUP to reload configuration files and open/close log files.
  2. SIGKILL (9) – Kill signal. Use SIGKILL as a last resort to kill process. This will not save data or cleaning kill the process.
  3. 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.
Nixcraft

Advertisements