How-To Geek
How to Manage Processes from the Linux Terminal: 10 Commands You Need to Know

The Linux terminal has a number of useful commands that can display running processes, kill them, and change their priority level. This post lists the classic, traditional commands, as well as some more useful, modern ones.
Many of the commands here perform a single function and can be combined — that’s the Unix philosophy of designing programs. Other programs, like htop, provide a friendly interface on top of the commands.
top
The top command is the traditional way to view your system’s resource usage and see the processes that are taking up the most system resources. Top displays a list of processes, with the ones using the most CPU at the top.


To exit top or htop, use the Ctrl-C keyboard shortcut. This keyboard shortcut usually kills the currently running process in the terminal.
htop
The htop command is an improved top. It’s not installed by default on most Linux distributions — here’s the command you’ll need to install it on Ubuntu:
sudo apt-get install htop


htop displays the same information with an easier-to-understand layout. It also lets you select processes with the arrow keys and perform actions, such as killing them or changing their priority, with the F keys.
We’ve covered htop in more detail in the past.
ps
The ps command lists running processes. The following command lists all processes running on your system:
ps -A


This may be too many processes to read at one time, so you can pipe the output through the less command to scroll through them at your own pace:
ps -A | less
Press q to exit when you’re done.
You could also pipe the output through grep to search for a specific process without using any other commands. The following command would search for the Firefox process:
ps -A | grep firefox


pstree
The pstree command is another way of visualizing processes. It displays them in tree format. So, for example, your X server and graphical environment would appear under the display manager that spawned them.


kill
The kill command can kill a process, given its process ID. You can get this information from the ps -A, top or pgrep commands.
kill PID


Technically speaking, the kill command can send any signal to a process. You can use kill -KILL or kill -9 instead to kill a stubborn process.
pgrep
Given a search term, pgrep returns the process IDs that match it. For example, you could use the following command to find Firefox’s PID:
pgrep firefox


You can also combine this command with kill to kill a specific process. Using pkill or killall is simpler, though.
pkill & killall
The pkill and killall commands can kill a process, given its name. Use either command to kill Firefox:
pkill firefox
killall firefox


We’ve covered pkill in more depth in the past.
renice
The renice command changes the nice value of an already running process. The nice value determines what priority the process runs with. A value of -19 is very high priority, while a value of 19 is very low priority. A value of 0 is the default priority.
The renice command requires a process’s PID. The following command makes a process run with very low priority:
renice 19 PID


You can use the pgrep trick above with renice, too.
If you’re making a process run at a higher priority, you’ll require root permissions. On Ubuntu, use sudo for that:
sudo renice -19 #
xkill
The xkill command is a way of easily killing graphical programs. Run it and your cursor will turn into an x sign. Click a program’s window to kill that program. If you don’t want to kill a program, you can back out of xkill by right-clicking instead.


You don’t have to run this command from a terminal — you can also press Alt-F2, type xkill and press Enter to use it from a graphical desktop.
We’ve covered binding xkill to a hotkey to easily kill processes.
Do you have a favorite command we didn’t mention here, or another trick to share? Leave a comment and let us know.
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (15)
Chris Hoffman is a technology writer and all-around computer geek. He's as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.
- Published 03/2/12




Excellent list. I learned a few things … as a long-time UNIX/Linux user, some of the commands seem new to me and may replace a few aliases I’ve had for 15+ years.
For example, pgrep appears to replace this:
alias psg=’ps -eaf |grep -v grep | grep $* ‘
With pgrep, you get the pid, but it doesn’t let you double check the result is actually the process you want. My alias uses the older options, which may work better cross-platform – I know it used to work on 6 other UNIX platforms, assuming you setup your path for BSD, not sysv, versions of the commands.
Nice article, thanks! I recently started using Ubuntu on my netbook, and I like it. Your article will be useful to me as I learn about Linux. Keep up the good work.
Hmm. I must have missed the part about the pstree. Good to know.
Always nice to have yet another “cheat sheet” of useful commands. Love the site by the way I visit it daily. Keep up the great work.
Thanks HTG, you always keep the learning process going. I knew a few but learned a bunch too, will be installing HTOP when I get home. I’ve been using various Linux distros for a couple of years now and trying to get more in-depth with some of the uses. The one I’ve had issues and can’t figure out and maybe this is the prime place to ask is, how do I start a new process in Linux (BASH) from a separate thread from the shell that launched it.
I’ll use Windows to draw the comparison because that is the function that I’m trying to emulate in BASH. Make the assumption that any exe in Windows called I need is already included in the system path I’m trying to do. In Windows I want to start Firefox from the command line, I would use;
start firefox
That would launch Firefox from a new separate memory space from the Windows command line. What is that ‘start’ command in BASH or any other Linux shell to launch a new process but not tie up the shell until that process terminates?
i.e. “start” rhythmbox
Thank you in advance.
-JP
JP -
you could type
firefox&
That starts the program in background.
Or, start it and then type ctrl-z followed by ‘bg’ to recover the console.
Firefox
bg
Hi JP,
Appending an ampersand ( & ) to the command runs the job in the background.
rhythmbox &
I didn’t know “htop”. Thanks for the tip ! :)
Awesome, thank you both Alan & Willm
Good to know about the How to Manage Processes from the Linux Terminal .
Below is a useful little script I wrote years ago while exploring AWK.
#!/bin/sh
ps -lA | grep “$1″ | awk ‘BEGIN { print “——————————–” } \
BEGIN { print “PID” “\t” “PPID” “\t” “NAME” } \
BEGIN { print “——————————–” } \
{ print $4 “\t” $5 “\t” $14 } \
END { print “——————————–” } ‘
I have been using unix/linux for about 16 years now, and I still learned something new from this (pstree — hello!)
Thanks!
All of this is IIRC: you can also exit top by pressing q, view a specific user’s processes with u username (e.g. u root or u howtogeek) and move up and down the list with .
Been with UNIX since the Berkley days. Still learning more. Thanks for the excellent article….
You only “need” to know 5 (maybe 6 with killall), the others are just either fancier (or uglier) versions of the same, or not really necessary.
i.e.
top
kill
ps
fg
bg
(plus killall, and things like grep and |)
Also the job control stuff, ctrl-z, &, [job number] and %syntax for job numbers are fairly useful for CLI process management.