Kill Process in Linux or Terminate a Process in UNIX / Linux Systems
2013-12-27 12:27
661 查看
Iam
a new Linux system user. How do 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 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.
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.
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:
OR use the combination of and grep
command:
Sample outputs:
Fig.01: Find the process ID (PID) of a running firefox program and apache2 server.
The syntax is:
Rules are simple:
You can kill all your own process.
Only root user can kill system level process.
Only root user can kill process started by other users.
In this example, I am going to kill lighttpd server.
Use the ps or pidof command to find out PID for any program. For example, if process name is lighttpd, you can use any one of the following command to obtain process ID:
Sample outputs:
OR
Sample outputs:
The PID # 3486 is assigned to the lighttpd process. To kill the lighttpd server, you need to pass a PID as follows:
OR
This will terminate a process with a PID of 3486.
Use the ps or pidof command:
If no signal specified in the kill command, signal # 15 (SIGTERM), is sent by default. So thekill 3486 command is same as the following command:
OR
Sometime signal # 15 is not sufficient. For example, lighttpd may not be killed by signal #15 due to open sockets. In that case process (PID) # 3486 would be killed with the powerful signal # 9:
OR
Where,
-9 or -SIGKILL - A special kill signal that nearly guarantee to kill the process with the iron fist.
The syntax is as follows to kill two or more PIDs as required can be used in a single 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. Do not use killall command on Unix operating systems. This is a Linux specific command.
To kill the lighttpd server, enter:
OR
To kill the Firefox web-browser process, enter:
As I said earlier, the killall command on UNIX-like system does something else. It kills all process and not just specific process. Do not use killall on UNIX system.
http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/
a new Linux system user. How do 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 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.
Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | kill |
Estimated completion time | 10 minutes |
A list of common Term singles
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 PIDis 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 and grep
command:
ps aux | grep httpd ps aux | grep apache2 ps aux | 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 system level process.
Only root user can kill process started by 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 any program. For example, if process name is lighttpd, you can use any one of the following command to obtain process ID:pidof lighttpd
Sample outputs:
3486
OR
ps aux | 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, you need to pass a PID as follows:# kill 3486
OR
$ sudo kill 3486
This will terminate a process with a PID of 3486.
How do I verify that 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 # 15 (SIGTERM), is 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 # 15 is not sufficient. For example, lighttpd may not be killed by signal #15 due to open sockets. In that case process (PID) # 3486 would be 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.
How can I kill two or more PIDs?
The syntax is as follows to kill two or more PIDs as required can be used in a single command:kill pid1 pid2 pid3 kill -15 pid1 pid2 pid3 kill -9 pid1 pid2 pid3 kill -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. Do not 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 something else. It kills all process and not just specific process. Do not use killall on UNIX system.
http://www.cyberciti.biz/faq/kill-process-in-linux-or-terminate-a-process-in-unix-or-linux-systems/
相关文章推荐
- Hadoop学习常用的Linux命令
- Linux用户空间与内核空间
- 意想不到的有趣linux命令
- CentOS安装gcc--RPM
- Linux下的串口编程(二)
- arch/alpha/include/asm/posix_types.h
- linux 系统自动定制运行 crontab
- Linux中eclipse配置编译TBB
- Linux下安装与配置snmp服务
- linux目录与进程
- Kali Linux开启SSH
- centos编译vim7.4支持python2.6
- linux0.00 "head.s"程序详解
- 关于linux服务器的批量维护、批量升级、
- linux下挂载移动硬盘和U盘的方法
- 嵌入式 LinuxC如何打印64bit的longlong整型int64_t
- Linux Crontab 定时任务命令详解
- Linux 快捷键 备忘
- Linux--VIM 中文显示乱码解决
- linux信号中断学习