kill linux command guide

How To Use Kill: The Complete Linux Command Guide

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

The “kill” command on Linux is a powerful tool that terminates processes running on your system. You’ll generally use it to stop a misbehaving application or to manage system resources efficiently. I’ve summarized the main options in this article.

The “kill” command allows users to terminate, interrupt, pause, or resume processes by specifying the process identifier on Linux.

I’ll start with the main syntax, and then show you examples and tips. Feel free to use the table of contents below if you already know the basics.

If you need help with Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your system. Click here to get it for free!

Command syntax

The basic syntax of the “kill” command is straightforward:
kill <options> <PID>

In this syntax, we have two main parameters:

  • PID refers to the process identifier. Each process running on your system has a number assigned to it. Using this number tells the system which process you want to stop.
  • The options in this command are mostly used to decide which signal to send to stop the process (more on that later).

Usage examples

How to find the PID for a Linux process

Before using the “kill” command, find the PID of the process you want to terminate.

You can do this using various methods, such as the `ps` command or `pgrep.`
For example:
ps aux | grep <process name>
or
pgrep <process name>

You might also like: I tried to replace my main PC with a Pi 5, here's what happened.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

After running the ps command, you will see the PIDs that match the process name you searched for. In the example above, Nginx is running 3 processes with PIDs 782, 783, and 785.

Once you have these processes’ IDs, you have everything you need to use the command “kill” with the syntax given above. It’s a great command for figuring out what’s slowing your system down.

Terminating a single process

In most cases, you’ll use “kill” to stop a single process, only adding its ID in the parameter.

Prefer reading without ads and popups?
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In

To terminate a single process, simply use the kill command followed by the PID for that process. For instance:
kill 4941

This command sends the default termination signal (SIGTERM) to the process with PID 4941.

Terminating multiple processes

You can also terminate multiple processes at once by specifying multiple PIDs:
kill 4941 2215 331

This command terminates processes with PIDs 4941, 2215, and 331.

Also: Yes, you can access your Pi from anywhere. Here's how.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

Note: If you find several PIDs when using the “ps” command, they may be linked together, so killing one may stop all of them. For example, a bash script often generates child processes that will be stopped automatically when you kill the parent.

Main options

The kill command doesn’t have many options, as explained in the command syntax. The only useful one is to specify which signal is sent to the process when it is killed.

By default, kill sends the SIGTERM signal, which instructs the process to terminate. However, you can specify a different signal using the – option.

Some common signals include:

  • SIGINT (Interrupt): This signal is often sent by pressing Ctrl+C in the terminal:
    kill -SIGINT 331
  • SIGKILL (Kill): This signal immediately terminates the process without any cleanup:
    kill -SIGKILL 4941
  • SIGSTOP (Stop): This signal pauses the process:
    kill -SIGSTOP 2215
  • SIGCONT (Continue): This signal resumes a stopped process:
    kill -SIGCONT 2215

I included these signals in this article to be thorough, but I have rarely used them in my years as a sysadmin, so it’s probably no big deal if you don’t remember them.

Tips

While the kill command syntax is pretty simple, I still have a few tips that I want to share with you.

Terminating processes using sudo

First, you won’t necessarily be able to kill any process you want with your current user.

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

You might also like: No screen? No problem! Here's how to setup a Pi without one.

Some processes may require administrator privileges to terminate.

In such cases, if you try to terminate the process without root privileges, you will get an “Operation not permitted error.” That’s typically the case for system services, scheduled tasks and other applications started by other users on your system.

To bypass this, use sudo:
sudo kill 5574

Sending kill signals to process groups

On Linux, a process group is a collection of one or more processes that are identified together.

You get the process group ID similarly to the process identifiers, with the “ps” command:
ps -eo pid,pgid,cmd

You can then use the process group ID to terminate all the processes in the process group.
You do this by specifying a negative PID:
kill -TERM -5658

Graceful vs. forceful termination

One last thing you must know about the “kill” command is the difference between stopping a process “gracefully” and “forcefully”:

Always Forgetting Linux Commands?
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.

Download now

Read next: No screen? No problem! Here's how to setup a Pi without one.

  • Graceful termination allows a process to perform cleanup tasks (such as saving data) and exit in an orderly manner. Graceful termination is initiated by sending the SIGTERM signal.
  • Forced termination, on the other hand, kills a process immediately without allowing it to clean up. Forced termination is done by sending the SIGKILL signal.

You should perform graceful termination whenever possible (the default option). Forceful termination should only be used when processes are unresponsive.

Related questions

What is the difference between SIGTERM and SIGKILL?

SIGTERM allows processes to perform cleanup tasks before termination. SIGKILL immediately terminates the process without any cleanup.

How do I send a signal to a specific user’s processes?

You can use the `pkill` command with the -u option to send signals to processes owned by a specific user:
pkill -u <username>

Can I terminate a process by name instead of PID?

Yes, you can! Again, you make use of the `pkill` command and pass to it the name of the process you want to terminate:
pkill firefox


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Prefer videos over reading? The RaspberryTips Community members get exclusive video lessons every month. Join now and watch them all right away. Get instant access.

Going further

The “kill” command offers even more functionality. For example, you can send custom signals or manage process priorities.

This is pretty advanced stuff, but you can get further details and a comprehensive list of command options by looking up the “kill” manual by running:
man kill

Whenever you're ready, here are other ways I can help you:

Master Linux Commands: Overwhelmed with Linux commands? This book is your essential guide to mastering the terminal. It includes practical tips, real-world examples, and a bonus cheat sheet to keep by your side.

The RaspberryTips Community: Need help with Linux or want to chat with people who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct support.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts