Linux

How to check running process in Ubuntu using command line

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

One can use the Ubuntu 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.

Check running process in Ubuntu

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

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

Please note that [[email protected]:~]$ is my shell prompt. You need to type all commands after that prompt.

How to manage processes from the Ubuntu terminal

The ps command is a traditional Ubuntu Linux command to lists running processes. The following command shows all processes running on your Ubuntu based system:
[[email protected]:~]$ ps -aux
[[email protected]:~]$ sudo ps -a

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

esha 42421  0.0  0.0 13160 8452  -  S    22:18   0:00.03 firefox

Where,

  1. esha – User name
  2. 42421 – PID (Ubuntu Linux process ID)
  3. 22:18 – Process start time
  4. firefox – Actual process or command

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:
[[email protected]:~]$ ps -aux | more
[[email protected]:~]$ sudo ps -aux | less

Press q to exit from above Ubuntu Linux pagers. You can search for a particular Ubuntu process using grep command/egrep command:
[[email protected]:~]$ ps aux | grep nginx
[[email protected]:~]$ sudo ps aux | grep vim
[[email protected]:~]$ sudo ps -aux | egrep 'sshd|openvpn'

pgrep command

Ubuntu comes with the pgrep command to search/find process. The syntax is:
[[email protected]:~]$ pgrep process
[[email protected]:~]$ sudo pgrep sshd
[[email protected]:~]$ pgrep vim
[[email protected]:~]$ pgrep -l test.sh

Given a search term, Ubuntu 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.

top command

The top command is another highly recommended method to see your Ubuntu servers resource usage. One can see a list of top process that using the most memory or CPU or disk. Run:
[[email protected]:~]$ top
[[email protected]:~]$ sudo top
[[email protected]:~]$ sudo top [options]

Check running process in Ubuntu Linux using top command

Ubuntu kill command

Want to kill a process on Ubuntu? Try kill command. The syntax is:
[[email protected]:~]$ kill pid
[[email protected]:~]$ kill -signal pid

Find PID using ps, pgrep or top command. Say you want to kill a PID # 25123, run:
[[email protected]:~]$ kill 25123
For some reason if the process can not be killed, try forceful killing:
[[email protected]:~]$ kill -9 25123
OR
[[email protected]:~]$ kill -KILL 25123
Ubuntu kill command to kill a process, given its process ID

pkill command

If you wish to kill a process by name, try pkill command on Ubuntu. The syntax is:
[[email protected]:~]$ pkill processName
[[email protected]:~]$ pkill vim
[[email protected]:~]$ pkill firefox
[[email protected]:~]$ pkill -9 emacs
[[email protected]:~]$ sudo pkill -KILL php7-fpm

killall command

The killall command kills processes by name, as opposed to the selection by PID as done by kill command:
[[email protected]:~]$ killall vim
[[email protected]:~]$ killall -9 emacs

Ubuntu kill a process given its name

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 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 18.04 LTS server. You can set a very low priority, enter:
[[email protected]:~]$ nice -n 13 cc -c *.c &
Set a very high priority for a kernel update. Before rebooting Ubuntu server, run:

[vivek@ubuntuLTS:~]$  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:
[[email protected]:~]$ renice {Priority} -p {PID}
[[email protected]:~]$ renice {Priority} {PID}
[[email protected]:~]$ pgrep vim
[[email protected]:~]$ renice 10 69947
[[email protected]:~]$ sudo renice -10 $(pgrep vim)

Ubuntu change the priority of a running process

Conclusion

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

Tags
Show More

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close