Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

Kill Command in Linux - DesignLinux

Sep 11 2020
designlinux 0 Comments
Kill Command in Linux

Kill command is a built in command in Linux which is used to terminate the process manually. This is commonly happening like, some applications may become unresponsive or start consuming a lot of system resources. In such situation the only solution is to either restart the system or kill the application process. You can terminate the process using several utilities but the kill command is most commonly used.

Make sure you are logged in as root or user with sudo privileges.

kill Command#

The command behavior is slightly different between the shells and the standalone /bin/kill executable. Use the type command to display all locations on your system containing kill:

type -a kill
kill is a shell builtin
kill is /bin/kill

In the above output you can see that the shell built-in has priority over the standalone executable, and it is used whenever you type kill. You can use the binary by typing the full path to the file /bin/kill. Here, we are using the Bash built-in.

Following is the basic syntax for the kill command:

kill [OPTIONS] [PID]...

The kill command sends a signal to specified processes or process groups, causing them to act according to the signal. When the signal is not specified, it defaults to -15 (-TERM).

The most commonly used signals are:

  • 1 (HUP) – Reload a process.
  • 9 (KILL) – Kill a process.
  • 15 (TERM) – Gracefully stop a process.

You can get the list of all available signals, by using the -l option:

kill -l

Signals can be specified in three different ways:

  • Using number (e.g., -1 or -s 1).
  • Using the “SIG” prefix (e.g., -SIGHUP or -s SIGHUP).
  • Without the “SIG” prefix (e.g., -HUP or -s HUP).

Following commands are the same to each other:

kill -1 PID_NUMBER
kill -SIGHUP PID_NUMBER
kill -HUP PID_NUMBER

Terminating Processes Using the kill Command#

To kill a process or terminate using kill command, first you need to find the process ID (PID). You can find PID using the different commands like top, ps, pidof and pgrep.

For example, to terminate the process of a chrome browser, you need to find the PID using pidof command:

pidof chrome

It will print the all process IDs of Chrome.

425 463 490 502

Once you have the process ID, you can kill them by sending the TERM signal:

kill -9 2551 2514 1963 1856 1771

You can combine the above commands into one, Instead of searching for PIDs and then terminating the processes:

kill -9 $(pidof chrome)

Reloading Processes Using the kill Command#

The kill command is also used to send the HUP signal, which tells the processes to reload its settings.

For example, if you want to reload the Nginx server, you need to send a signal to the master process. The nginx.pid file located at /var/run which contains the process ID of the Nginx master process. Use the cat command to find the master PID:

cat /var/run/nginx.pid
10235

Once you found the master PID reload the Nginx settings by typing:

sudo kill -1 10235

Conclusion#

The kill command is used to send a signal to processes and mostly SIGKILL or -9 signal is used to terminate the given processes.

If you have any questions or feedback, feel free to leave a comment.

Related

Tags: kill, terminal

How to Install and Configure Fail2ban on CentOS 8

Prev Post

The 10 Best Rolling Release Linux Distributions

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 1
  • 87
  • 605,837

DesignLinux.com © All rights reserved

Go to mobile version