Sometimes, I need to kill a process in Linux. So, how can I do that ? In this article, i will explain how do I kill process in Linux.
Kill process using PID (Using kill command)
kill command sends a signal to a specified process. If no signal is specified, the TERM signal is sent. The TERM signal will kill a process. For a list of possible signals, type ‘man 7 signal’ in a terminal window.
First you must determine the PID of the process you want to kill. This can be done usually pretty easily with the ps command in Linux. Example, find process ID of mysqld, type the following command
# ps aux | grep mysql
Output
mysql 1815 0.0 0.2 254112 3844 ? Ssl May16 0:51 /usr/sbin/mysqld
Finally, kill process using PID. Above command tell you PID (1815) of mysqld process. Now kill process using this PID:
# kill 1815
Or
# kill -9 1815
Note: “-9” option is special Kill signal which will kill the process and cannot be blocked. Do not issue “kill -9” to a process connected to a database or to a database engine process.
Using top command
Example, I will kill mysqld process, First, type the following command as root
# top
On screen, process id of mysql is 1815. I will press “k” and enter: 1815 to kill mysqld process. The screen will look like
Kill processes by name
You can use killall command. The killall command kill processes by name. Example kill mysqld processes, type the following command
# killall mysqld
Or
# killall -9 mysqld
Related Posts:
- 10 lsof Command Examples
- How To Find Hard Drive Specifications
- Install RPM File On CentOS / RedHat
- How To Install Subversion (SVN) Extension Working With PHP 5.3
- How To Setup Iptables Firewall For A Web Server On CentOS
- How Do I Fix “Host is blocked because of many connection error” In MySQL
- How To Start / Shutdown / Reboot Guest Operating Systems With virsh Command On KVM
- Repel port flood by CSF and IPT_Recent
- What is the role of this variables in php.ini file (expose_php – allow_url_fopen – register_globals) ?
- How Do I Block An IP Address On Linux Server ?