• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Kill a Process in Linux

Thumbnail for Shawn TabaiThumbnail for Shawn TabaiThumbnail for Shawn TabaiThumbnail for Shawn Tabai
Shawn Tabai

Shawn Tabai

Software Engineer, Actual

Published: 2/1/2024

About Terminus

Finding and Killing Processes

The pkill command can be used to stop / kill all processes that match its pattern from the command line:

pkill -aif warp

If you want to be more precise, the kill command can be used to quit a particular process by specifying its process ID:

kill 2934

There are a number of ways you can discover the IDs of running processes depending on what you know about the process.

Searching For The Right Process To Kill

You can search for a process by:

  • The command name that was executed to spawn it:
    pgrep -aifl firefox
  • The user that executed it:
    pgrep -u root
  • A network port it's using:
    lsof -i tcp:8888
  • A file it has open:
    lsof /dev/null

Force Killing Processes

If the process doesn't end, you can force kill the process by sending it the SIGKILL signal. To do this, simply add the -9 argument to kill or pkill:

pkill -9 -aif firefox

pkill and pgrep vs. killall and ps

killall and ps are the old-fashioned equivalents of pkill and pgrep. They're now generally discouraged because they behave very differently and are somewhat hard to use. Some versions of Linux may not even provide killall.

If you still want to use killall, you might have difficulty targeting the right process, but you can try the following:

killall Firefox

💡Tip for Warp Users

If these commands don't find any matching processes, they will often silently exit with no notice that it didn't work other than a nonzero return code. Warp users will notice that the terminal block is helpfully made red to indicate that the process failed.

Thumbnail for Thumbnail for Thumbnail for Thumbnail for

Process Signals

By default, running kill or pkill sends the SIGTERM signal to the specified process, which is the polite way to ask the process to terminate. The process can choose to ignore or handle this signal rather than ending, either purposefully or because the process is misbehaving.

Signals you can send include:

  • 2 - SIGINT - Interrupt the program (equivalent to pressing Ctrl+C on the terminal)
  • 9 - SIGKILL - Forcibly terminate the program immediately (cannot be ignored or handled)
  • 15 - SIGTERM (default) - Request that the program terminate (can be ignored or handled)

Command Portability

Some of these commands and their flags may behave slightly differently on different operating systems. Favoring pkill (instead of killall) and pgrep (instead of ps) can help reduce these issues. All of the specific invocations listed above will work on both Linux and MacOS.

Written by

Thumbnail for Shawn TabaiThumbnail for Shawn TabaiThumbnail for Shawn TabaiThumbnail for Shawn Tabai
Shawn Tabai

Shawn Tabai

Software Engineer, Actual

Filed Under

Related Articles

List Open Ports in Linux

Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.

UnixLinux
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Count Files in Linux

Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.

LinuxUnix
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

How to Check the Size of Folders in Linux

Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.

LinuxUnix
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

Linux Chmod Command

Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.

Linux
Thumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan LudosanuThumbnail for Razvan Ludosanu
Razvan Ludosanu

POST JSON Data With Curl

How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.

BashUnixLinux
Thumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran GulThumbnail for Neeran Gul
Neeran Gul

Format Command Output In Linux

Learn how to filter and format the content of files and the output of commands in Linux using the awk command.

Linux

Create Groups In Linux

Learn how to manually and automatically create and list groups in Linux.

Linux

Switch Users In Linux

Learn how to switch between users, log in as another user, and execute commands as another user in Linux.

Linux

Remover Users in Linux

Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.

Linux

Delete Files In Linux

Learn how to selectively delete files in Linux based on patterns and properties using the rm command.

Linux

Find Files In Linux

Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.

Linux

Copy Files In Linux

Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.

Linux

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Request demo
Thumbnail for nullThumbnail for nullThumbnail for nullThumbnail for null