Linux

How to check running process in Ubuntu Linux using command line

[ad_1]

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 {[email protected]:~}$ 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:
{[email protected]:~}$ ps -aux
{[email protected]:~}$ sudo ps -a
{[email protected]:~}$ sudo ps -U vivek
{[email protected]:~}$ 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:
{[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 Linux process using grep command/egrep command:
{[email protected]:~}$ ps aux | grep nginx
{[email protected]:~}$ sudo ps aux | grep vim
{[email protected]:~}$ sudo ps aux | grep chromium-browser
{[email protected]:~}$ 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:
{[email protected]:~}$ pgrep process
{[email protected]:~}$ sudo pgrep sshd
{[email protected]:~}$ pgrep vim
{[email protected]:~}$ pgrep chromium-browser
{[email protected]:~}$ 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.
{[email protected]-box:~}$ top
{[email protected]:~}$ sudo top
{[email protected]:~}$ 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:
{[email protected]:~}$ htop
{[email protected]:~}$ sudo htop
{[email protected]:~}$ 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:
{[email protected]:~}$ kill pid
{[email protected]:~}$ kill -signal pid

Find PID using ps, pgrep or top command. Say you want to kill a PID # 3932, run:
{[email protected]:~}$ kill 3932
For some reason if the process can not be killed, try forceful killing:
{[email protected]:~}$ kill -9 3932
OR
{[email protected]:~}$ 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:
{[email protected]:~}$ pkill processName
{[email protected]:~}$ pkill vim
{[email protected]:~}$ pkill firefox
{[email protected]:~}$ pkill -9 emacs
{[email protected]:~}$ 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:
{[email protected]:~}$ killall vim
{[email protected]:~}$ 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:
{[email protected]:~}$ 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:
{[email protected]:~}$ renice {Priority} -p {PID}
{[email protected]:~}$ renice {Priority} {PID}
{[email protected]:~}$ pgrep vim
renice 10 69947
{[email protected]:~}$ 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.

[ad_2]

Facebook Comments

Show More

Leave a Reply

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

Back to top button