I am a new Ubuntu sysadmin for the Ubuntu Linux operating system. How do I check running process in Ubuntu Linux using the command line option?

One can use the Ubuntu Linux command line or terminal app to display a running process, change their priorities level, delete process and more. This page shows how to use various commands to list, kill and manage process on Ubuntu Linux.

Check running process in Ubuntu Linux

The procedure to monitor the running process in Ubuntu Linux using the command line is as follows:

  1. Open the terminal window on Ubuntu Linux
  2. For remote Ubuntu Linux server use the ssh command for log in purpose
  3. Type the ps aux command to see all running process in Ubuntu Linux
  4. Alternatively, you can issue the top command/htop command to view running process in Ubuntu Linux

Let us see some example and usage for Ubuntu Linux in details.

NOTE: Please note that {vivek@ubuntu-box:~}$ is my shell prompt. You need to type commands after the $ prompt.

How to manage processes from the Ubuntu Linux terminal

The ps command is a traditional Ubuntu Linux command to lists running processes. The following command shows all processes running on your system:
{vivek@ubuntu-box:~}$ ps -aux
{vivek@ubuntu-box:~}$ sudo ps -a
{vivek@ubuntu-box:~}$ sudo ps -U vivek
{vivek@ubuntu-box:~}$ ps -U tom

How to Manage Processes from the Ubuntu Linux Terminal
The process ID (PID) is essential to kill or control process on Ubuntu Linux. For example consider the following outputs:

vivek 30992 0.0 0.3 40092 3492 pts/0 R+ 06:31 0:00 ps -U vivek -au

Where,

  1. vivek – User name
  2. 30992 – PID (Ubuntu Linux process ID)
  3. 06:31 – Process start time
  4. ps -U vivek -au – Actual process or command with command line arguments

There may be too many processes. Hence, it uses the following less command/more command as pipe to display process one screen at a time:
{vivek@ubuntu-box:~}$ ps -aux | more
{vivek@ubuntu-box:~}$ sudo ps -aux | less

Press q to exit from above Ubuntu Linux pagers. You can search for a particular Ubuntu Linux process using grep command/egrep command:
{vivek@ubuntu-box:~}$ ps aux | grep nginx
{vivek@ubuntu-box:~}$ sudo ps aux | grep vim
{vivek@ubuntu-box:~}$ sudo ps aux | grep chromium-browser
{vivek@ubuntu-box:~}$ sudo ps -aux | egrep 'sshd|openvpn'

Ubuntu Linux pgrep command

Many variants of Ubuntu Linux comes with the pgrep command to search/find process. The syntax is:
{vivek@ubuntu-box:~}$ pgrep process
{vivek@ubuntu-box:~}$ sudo pgrep sshd
{vivek@ubuntu-box:~}$ pgrep vim
{vivek@ubuntu-box:~}$ pgrep chromium-browser
{vivek@ubuntu-box:~}$ pgrep -l nginx

Given a search term, Ubuntu Linux pgrep command shows the process IDs that match it
The -l option passed to the pgrep command to display long format and process name too.

Ubuntu Linux top and htop commands

The top command is another highly recommended method to see your Ubuntu Linux servers resource usage. One can see a list of top process that using the most memory or CPU or disk.
{vivek@ubuntu-box:~}$ top
{vivek@ubuntu-box:~}$ sudo top
{vivek@ubuntu-box:~}$ sudo top [options]

Check running process in Ubuntu Linux using top command
The htop is easy to use process viewer from the CLI on Ubuntu Linux. Try it as follows:
{vivek@ubuntu-box:~}$ htop
{vivek@ubuntu-box:~}$ sudo htop
{vivek@ubuntu-box:~}$ sudo htop [options]

How to view running process in Linux using htop
Press q to exit from above top/htop Ubuntu Linux commands.

Ubuntu Linux kill command

Want to kill a process? Try kill command. The syntax is:
{vivek@ubuntu-box:~}$ kill pid
{vivek@ubuntu-box:~}$ kill -signal pid

Find PID using ps, pgrep or top command. Say you want to kill a PID # 3932, run:
{vivek@ubuntu-box:~}$ kill 3932
For some reason if the process can not be killed, try forceful killing:
{vivek@ubuntu-box:~}$ kill -9 3932
OR
{vivek@ubuntu-box:~}$ kill -KILL 3932
Ubuntu Linux kill command to kill a process, given its process ID

Ubuntu Linux pkill command

If you wish to kill a process by name, try pkill command. The syntax is:
{vivek@ubuntu-box:~}$ pkill processName
{vivek@ubuntu-box:~}$ pkill vim
{vivek@ubuntu-box:~}$ pkill firefox
{vivek@ubuntu-box:~}$ pkill -9 emacs
{vivek@ubuntu-box:~}$ sudo pkill -KILL php7-fpm

Ubuntu Linux killall command

The killall command kills processes by name, as opposed to the selection by PID as done by kill command:
{vivek@ubuntu-box:~}$ killall vim
{vivek@ubuntu-box:~}$ killall -9 emacs

Unix kill a process given its name

Ubuntu Linux nice and renice command

The primary purpose of the nice command is to run a process/command at a lower or higher priority. Use the renice command to alter the nice value of one or more running Ubuntu Linux processes. The nice value can range from -20 to 19, with 19 being the lowest priority. Say, you want to compile software on a busy Ubuntu Linux server. You can set a very low priority, enter:
{vivek@ubuntu-box:~}$ nice -n 13 cc -c *.c &
Set a very high priority for a kernel update. Before rebooting Ubuntu Linux server, run:

nice --10 wall <<end
System reboots in 5 minutes for Ubuntu Linux kernel update! Save all your work!!! -- Sysadmin
end

To change the priority of a running process, type the following:
{vivek@ubuntu-box:~}$ renice {Priority} -p {PID}
{vivek@ubuntu-box:~}$ renice {Priority} {PID}
{vivek@ubuntu-box:~}$ pgrep vim
renice 10 69947
{vivek@ubuntu-box:~}$ sudo renice -10 $(pgrep vim)

Ubuntu Linux change the priority of a running process

Conclusion

This page shows how to manage the process on the Ubuntu Linux terminal. For further info see man pages or our example pages:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Similar Posts