How to end processes from the Linux terminal

Sometimes killing a process is the only way to get rid of it. Despite the harsh name, “killing” a process only means “forcing it to end”. Here’s how to do this from the Linux or macOS command line.

What is a process?

Running programs like your web browser, background processes associated with your desktop environment, and Linux system services are all processes.

You can divide processes into two groups:

  • Foreground processes are those that were started or started by a user. They can be in a terminal window or a graphical application.
  • Background processes are all processes that start automatically and have no interaction with users. They do not expect any input from users, nor do they present any results or outputs to them. Background processes are things like services and daemons.

If the foreground processes are the front of the theater staff and the actors, the background processes are the backstage team “behind the scenes”.

When processes are misbehaving or not working, they can consume too much CPU time, use up your memory, or get into a tight computing loop and stop responding. Graphic applications can refuse to respond to mouse clicks. Terminal applications may never bring you back to the command prompt.

The humane answer

“Killing” a process just means “forcing the process to terminate”. This may be necessary if the process refuses to respond.


Linux offers the kill, pkill, and killall Commands that allow you to do just that. These commands can be used with any type of process, graphic or command line, foreground or background.

The kill squad

Use kill, you need to know the Process ID (PID) of the process you want to kill. the ps Command can be used to find the PID of a process.

Have ps search all processes -e (all processes) option. Piping of the outlet through less advisable, there will be quite a lot of them. Type ps, a space, -e, a space, | (a pipe character), another space, and then type less. Press Enter to execute the command.

ps -e | less

This will give you a process list similar to the screenshot below. You can search forward in less Use of / Button and you can search backwards with the button ? Key.

Output ps in one less window

To accurately identify the process you are interested in, route the output from ps by grep and enter the name – or part of the name – of the process.

ps -e | grep shutter

ps command passed through grep to find the locking process

Once you find the PID of the process you want to kill, pass it to the kill Command as a parameter. To end that shutter Process identified by the previous command use this command:

kill 2099


the kill Command is a silent assassin – he won’t give you any feedback if he’s successful.

The pkill command

the pkill The command allows you to end a process – or processes – by name. You don’t need to use the PID to identify the process. Use pkill You enter a search term that pkill used to check the list of running processes. Matching processes are ended. So you need to be sure that the search term is spelled correctly.

As a safety net, you can pgrep Command before using the pkill Command. the pgrep Command also accepts a search term. The PID of each process that matches the search term is listed. That’s for sure because pgrep won’t be a killSignal to the processes, and if you type the search term incorrectly, you won’t accidentally kill another process. You can make sure that you have thought out your search term before you pass it on to pkill. Both pkill and pgrep Treat the search term in the same way. Their treatment is so similar to that of them share the same man page.

Suppose there is a process with “subq” in its name. We’ll use that ps -u dave | grep Order to take a look behind the curtain. You can see that “subq” corresponds to this process and this process alone. That was just so you can see the full name of the process.

ps -u dave | grep subq

Let’s say our user didn’t do this; All they know is that the process name contains the substring “subq”. they use pgrep to check that there is only one match for the search term. You then use this search term pkill.

pgrep subq
pkill subq

You can use pkill kill multiple processes at once. Here the user runs pgrep to check how many processes Chrome has started. they use pkill kill them all. You then check with pgrep that they have all been removed.

pgrep chrome
pkill chrome
pgrep chrome


If you have multiple processes running with the same name but you don’t want to end all of them, you can pgrep with the -f (Command line) option to identify which process is which. A simple one example would be two ping Processes. You want to kill one of them, but not the other. You can use their command lines to distinguish them. Note the use of quotation marks to enclose the command line parameter.

pgrep -f "ping 192.168.4.22"
pkill -f "ping 192.168.4.22"

pgrep pkill with ping command line

The killall command

warning: In the Solaris and OpenIndiana operating systems, the killall Command terminates all processes owned by you. If you are root or if you have issued sudo killall You will restart your computer! While researching this article, this behavior was confirmed with the latest version of OpenIndiana Hipster 2018.10.

the killall command works similarly to the pkill Command, but with one specific difference. Instead of passing a search term to the command, you need to provide the exact process name.

You cannot provide a partial match to a process name; You need to provide the entire process name as shown:

killall shutt
killall shutter

the -y The (younger than) option allows you to terminate processes that have been running for less than a specified period of time. The period is given in numbers, followed by one of these units:

  • s (seconds)
  • m (minutes)
  • h (hours)
  • d (days)
  • w (weeks)
  • M (months, note, capital letter “M”)
  • j (years)

To a process called. to end ana that just started and leave all older instances of ana is running, you can use the following parameters with killallif you had responded within two minutes:

killall -y 2m ana

killall with younger as an option


the -o The (older than) option enables you to terminate processes that have been running for longer than a specified period of time. This order will kill everyone ssh Connections that run for more than a day:

killall -o 1d sshd

Don’t be too happy

These commands enable you to correctly identify and terminate faulty processes with accuracy and certainty.

Always be careful. First of all, make sure that the process you are trying to kill is really what you want it to be. Second, double check – be careful and make sure that the process you are aiming for is the one you want to end. Proceed to exit when you are satisfied.

Linux commands
Filestar · pv · cat · tac · chmod · grep · difference · sed · With · man · pushed · popd · fsck · Test disk · seq · fd · pandoc · CD · $ PATH · awk · join · jq · wrinkles · unique · Journalctl · tail · stat · ls · fstab · echo · fewer · chgrp · chown · rev · look · Strings · Type · rename · Postal code · unzip · assemble · ummount · To install · fdisk · mkfs · rm · rmdir · rsync · df · gpg · weather · Nano · mkdir · from · ln · Patch · Convert · rclon · Scraps · srm
Processesalias · screen · above · kind · renice · progress · strace · system · tmux · chsh · story · at · Batch · for free · which · dmesg · chfn · User mod · ps · chroot · xargs · tty · pinkie finger · lsof · vmstat · Time out · Wall · Yes sir · kill · sleep · sudo · it is · Time · groupadd · User mod · groups · lshw · switch off · start anew · Stop · switch off · passwd · lscpu · crontab · date · bg · fg
Networkingnetstat · Ring · Trace route · ip · ss · who is · fail2ban · bmon · she · finger · nmap · ftp · curl · wget · who · who am I · w · iptables · ssh-keygen · ufw

Best Linux Laptops for Developers and Enthusiasts

Related Posts