[Linux] End process __linux

Source: Internet
Author: User


Iam a new Linux system user. How does I kill process on Linux based server using command line options? How can I kill running process on Unix?

Linux and Unix-like operating system come with the kill command to terminates stalled or unwanted processes have 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, this 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, resort to kill process. This is 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 the A program. For example, the Firefox are a running process if you are browsing the Internet. The system is automatically assigned a unique process identification number (PID) for each time you start Firefox browser. A PID is automatically assigned to each process as 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 | grep httpd
ps| grep apache2
ps| grep  Firefox

Sample outputs:

Fig.01:find the Process ID (PID) of a running Firefox program and Apache2 server.

KILL command Syntax

The syntax is:

Kill [signal] PID kill
 -15 pid kill
 -9 pid kill
 -sigterm pid kill
[ options] -sigterm PID
What Linux or Unix permissions do I need to kill a process?

Rules are simple:you can kill all your own process. Only root user can kill the system level process. Only root user can kill process started by the other users. Kill command Examples

In this example, I am going to kill LIGHTTPD server. Step #1: Find out the PID (process ID)

Use the "PS" or "pidof command" to "find" out PID. For example, if process name was lighttpd, can use any one of the following command to obtain process ID:

pidof lighttpd

Sample outputs:

3486

OR

PS | grep lighttpd

Sample outputs:

LIGHTTPD  3486  0.0  0.1   4248 1432  ?        S    Jul31   0:00/usr/sbin/lighttpd-f/etc/lighttpd/lighttpd.conf
lighttpd  3492  0.0 0.5  13752  3936?        Ss   Jul31   0:00/USR/BIN/PHP5-CG
Step #2: Kill the process using a PID

The PID # 3486 is assigned to the LIGHTTPD process. To kill the LIGHTTPD server, your need to pass a PID as follows:
# Kill 3486
OR
$ sudo kill 3486
This is terminate a process with a PID of 3486. How do I verify which the process is gone/killed?

Use the PS or PIDOF command:
$ ps aux | grep lighttpd
$ pidof lighttpd A Note about sending stronger signal # 9 (SIGKILL)

IF no signal specified in the KILL command, Signal # (SIGTERM), are sent by default. So Thekill 3486 command is same as the following command:
# kill-15 3486
# kill-sigterm 3486
OR
$ sudo kill-15 3486
$ sudo kill-sigterm 3486

Sometime signal # is not sufficient. For example, LIGHTTPD May is killed by the signal #15 due to open sockets. In, case process (PID) # 3486 would is killed with the powerful signal # 9:
# kill-9 3486
# Kill-sigkill 3486
OR
$ sudo kill-9 3486
$ sudo kill-sigkill 3486
Where,-9 or-sigkill–a special kill signal that nearly guarantee to kill the process with the Iron Fist. can I kill two or more PIDs?

The syntax is as follows to kill two or more pids as required can being used in a single command:

Kill  Pid1 pid2 pid3
kill -15  pid1 pid2 pid3
kill -9 pid1 pid2 pid3
kill C12/>-9 3546 5557 4242
Say Hello to killall command

This is a Linux only command. To kill processes by name. So no need to find the PIDs using the ' pidof process ' or ' PS aux | grep process ' command. Don't use Killall command on Unix operating systems. This is a Linux specific command. The syntax is

Killall Process-name-here

To kill the LIGHTTPD server, enter:
# killall-15 LIGHTTPD
OR
# killall-9 LIGHTTPD
To kill the Firefox web-browser process, enter:
# killall-9 Firefox-bin

As I said earlier, the Killall command on unix-like system does else. It kills all process and not just specific process. Don't use Killall on UNIX system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.