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:

[vyga@ubuntuLTS:~]$ ps -aux
[vyga@ubuntuLTS:~]$ sudo ps -a

 

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,

 

esha – User name

42421 – PID (Ubuntu Linux process ID)

22:18 – Process start time

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:

[vyga@ubuntuLTS:~]$ ps -aux | more
[vyga@ubuntuLTS:~]$ 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:

[vyga@ubuntuLTS:~]$ ps aux | grep nginx
[vyga@ubuntuLTS:~]$ sudo ps aux | grep vim
[vyga@ubuntuLTS:~]$ sudo ps -aux | egrep 'sshd|openvpn'

 

pgrep command

Ubuntu comes with the pgrep command to search/find process. The syntax is:

[vyga@ubuntuLTS:~]$ pgrep process
[vyga@ubuntuLTS:~]$ sudo pgrep sshd
[vyga@ubuntuLTS:~]$ pgrep vim
[vyga@ubuntuLTS:~]$ pgrep -l test.sh

 

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:

[vyga@ubuntuLTS:~]$ top
[vyga@ubuntuLTS:~]$ sudo top
[vyga@ubuntuLTS:~]$ sudo top [options]

 

Ubuntu kill command

Want to kill a process on Ubuntu? Try kill command. The syntax is:

[vyga@ubuntuLTS:~]$ kill pid
[vyga@ubuntuLTS:~]$ kill -signal pid

 

Find PID using ps, pgrep or top command. Say you want to kill a PID # 25123, run:

[vyga@ubuntuLTS:~]$ kill 25123

 

For some reason if the process can not be killed, try forceful killing:

[vyga@ubuntuLTS:~]$ kill -9 25123

OR

[vyga@ubuntuLTS:~]$ kill -KILL 25123

 

pkill command

If you wish to kill a process by name, try pkill command on Ubuntu. The syntax is:

[vyga@ubuntuLTS:~]$ pkill processName
[vyga@ubuntuLTS:~]$ pkill vim
[vyga@ubuntuLTS:~]$ pkill firefox
[vyga@ubuntuLTS:~]$ pkill -9 emacs
[vyga@ubuntuLTS:~]$ 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:

[vyga@ubuntuLTS:~]$ killall vim
[vyga@ubuntuLTS:~]$ killall -9 emacs

 

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:

[vyga@ubuntuLTS:~]$ nice -n 13 cc -c *.c &

 

Set a very high priority for a kernel update. Before rebooting Ubuntu server, run:

 

[vyga@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:

[vyga@ubuntuLTS:~]$ renice {Priority} -p {PID}
[vyga@ubuntuLTS:~]$ renice {Priority} {PID}
[vyga@ubuntuLTS:~]$ pgrep vim
[vyga@ubuntuLTS:~]$ renice 10 69947
[vyga@ubuntuLTS:~]$ sudo renice -10 $(pgrep vim)

 

Was this answer helpful? 0 Users Found This Useful (0 Votes)