Sysadmin daily useful ps aux command examples in Linux

ps aux command
ps aux command

In this guide, We will see various types of Ps aux command examples. These examples would be useful in sysadmins’ daily tasks to monitor the running process on the system.

ps command Examples

  • ps command stands for processes status.
  • The ps command is used to find the running process on the system.
  • ps command gets the information about the process from a virtual file called ‘/proc’ filesystem.
  • It is the most important utility or command for sysadmins to monitor the running process which helps you to understand what’s going on in the system.

You can use the ps command in various ways to get the output but only some of them are actually used on a daily basis or practically.

In this tutorial, we are going to look at the top 10 ps aux command examples that are useful in your daily operations to monitor active running processes on the system.

1. Show All the process in a current shell

If you run only ps command without any arguments or parameters, it will give you current shell process in the output,

$ ps

PID TTY TIME CMD
4979 pts/8 00:00:00 bash
5711 pts/8 00:00:00 ps

2. Print all running process

If you want to check all the running process then use below ps command with argument,

$ ps -A or ps -e

1048 ?        00:00:00 polkitd
1138 ?        00:03:00 php-fpm7.0
1144 ?        00:00:00 systemd
1160 ?        00:00:00 php-fpm7.0
1161 ?        00:00:00 php-fpm7.0

3. To see every running process on the system

In the ps ax command, you will get all the running processes with the full-format command of the process. and ps aux the additional info of the running process like the user, CPU, a memory of that process.

you will see the difference in output below,

$ ps ax 

PID TTY   STAT   TIME COMMAND
1 ?       Ss     1:58 /sbin/init
2 ?       S      0:00 [kthreadd]
3 ?       S      0:22 [ksoftirqd/0]
5 ?       S<     0:00 [kworker/0:0H]
$ ps aux 

USER      PID %CPU %MEM VSZ   RSS TTY   STAT START   TIME COMMAND
root      1138  0.0   0.5 4636 1296 ?     Ss   Jul06   3:00 php-fpm
mysql     1144  0.0   0.1  4526  3856 ?     Ss   Jul06   0:00 mysql
www-data  1160  0.0   0.0 4636  1012 ?     S    Jul06   0:00 php-fpm
mysql     1163  0.0   0.0  3384  1252 ?     S    Jul06   0:00 (sd-pam)

4. To see every process on the system using standard syntax

Below command displays output with the full-format listing,

$ ps -ef

UID      PID   PPID   C STIME TTY     TIME CMD
root     14244  8646   0 Jul30 ?       00:00:00 sshd: [email protected]/6
root     14307 1424   0 Jul30 pts/6   00:00:00 -bash
root     18948  1234   0 Jul26 ?       00:00:00 /lib/systemd/systemd
root     18954 1894   0 Jul26 ?       00:00:00 (sd-pam)
root     20982  8647   0 Jul30 ?       00:00:37 sshd: [email protected]/4
root     21044 2098   0 Jul30 pts/4   00:00:00 -bash
www-data 30119 1909  0 06:25 ?     00:00:00 /usr/sbin/apache2 -k start

5. Display process own by you

The below command will display the active process which is own by the current user.

For example, if you are login with root user then the command will display an active process which is running with root user.

$ ps -xu

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.2 185336  5268 ?        Ss   Jul06   1:58 /sbin/init
root         2  0.0  0.0      0     0 ?        S    Jul06   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    Jul06   0:22 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S<   Jul06   0:00 [kworker/0:0H]
root         7  0.0  0.0      0     0 ?        S    Jul06   3:36 [rcu_sched]

6. Display processes by user name or id (UID)

$ ps -fu linuxgrow

UID       PID   PPID C STIME TTY    TIME CMD
linuxgrow     1048     1  0 Jul06 ?      00:00:00 /usr/lib/policykit-1
linuxgrow     1138     1  0 Jul06 ?      00:03:00 php-fpm
linuxgrow     1909     1  0 Jul06 ?     00:02:17 apach2
linuxgrow     2030     1  0 Jul06 ?      00:05:39 /usr/sbin/nmbd -D
linuxgrow     2138     1  0 Jul06 ?      00:00:28 postfix
$ ps -fu 1000

UID       PID   PPID   C STIME TTY     TIME CMD
linuxgrow     1048     1   0 Jul06 ?      00:00:00 /usr/lib/policykit-1
linuxgrow     1138     1   0 Jul06 ?      00:03:00 php-fpm
linuxgrow     1909     1   0 Jul06 ?     00:02:17 apach2
linuxgrow     2030     1   0 Jul06 ?      00:05:39 /usr/sbin/nmbd -D
linuxgrow     2138     1   0 Jul06 ?      00:00:28 postfix

7. List process by PID

This is mostly used the command on a daily basis. you run top command and found that one of an active process taking high CPU and you want to check which process is utilizing high CPU. That time copy the PID of that process and run with ps command as shown below,

$ ps  -fp  30119

UID        PID  PPID  C STIME TTY          TIME CMD
www-data 30119  1909  0 06:25 ?        00:00:00 /usr/sbin/apache2 -k start

8. List process with multiple PID’s

If you want to check active process of multiple PID then run below command,

$ ps  -fp  30119,1380,1138

root      1138     1  0 Jul06 ?       00:03:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
mysql     1380  1189  0 Jul06 ?        00:25:10 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql
www-data 30119  1909  0 06:25 ?        00:00:00 /usr/sbin/apache2 -k start

9. Display Process Tree

This command will help you to know how processes are linked to each other, processes whose parents have been killed are adopted by the init (or systemd).

$ ps -e --forest

PID TTY      TIME CMD
 1138 ?        00:03:00 php-fpm7.0
 1160 ?        00:00:00  \_ php-fpm7.0
 1161 ?        00:00:00  \_ php-fpm7.0
 1144 ?        00:00:00 systemd
 1163 ?        00:00:00  \_ (sd-pam)
 1189 ?        00:00:00 mysqld_safe
 1380 ?        00:25:10  \_ mysqld
 1909 ?        00:02:17 apache2
30119 ?        00:00:00  \_ apache2
30120 ?        00:00:00  \_ apache2

10. High CPU and Memory usage find top running process
$ ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

PID   PPID CMD                         %MEM %CPU
1380  1189 /usr/sbin/mysqld --basedir=  4.3   0.0
1909     1 /usr/sbin/apache2 -k start   1.4   0.0
3787  1909 /usr/sbin/apache2 -k start   0.7   0.0
3119  1909 /usr/sbin/apache2 -k start   0.7   0.0
3123  1909 /usr/sbin/apache2 -k start   0.7   0.0
3121  1909 /usr/sbin/apache2 -k start   0.6   0.0

11. Find active process with the process name

$ ps -ef | grep apache

root      1909     1  0 Jul06 ?        00:02:17 /usr/sbin/apache2 -k start
www-data  3786  1909  0 11:53 ?        00:00:00 /usr/sbin/apache2 -k start
www-data  3787  1909  0 11:53 ?        00:00:00 /usr/sbin/apache2 -k start
$ ps aux | grep ssh

root       864  0.0  0.2  65508  5116 ?        Ss   Jul06   0:00 /usr/sbin/sshd -D
root      4356  0.0  0.3  97052  7100 ?        Ss   13:38   0:00 sshd: [email protected]/1
root      4471  0.0  0.3  96960  6772 ?        Ss   Jul27   0:08 sshd: [email protected]/3
root      4903  0.0  0.3  96964  6780 ?        Ss   14:54   0:00 sshd: [email protected]/8

I hope you like the article if you find any difficulties then please do comment queries or problem via the comment section, till then stay tuned to Linuxgrow.com for more such valuable articles.

If you have any useful ps and ps aux command examples to share, use the comment box below.

Prashant

Welcome to Linuxgrow. I'm Prashant, a tech-blogger from Mumbai, India. I started Linuxgrow as a passion and to share my knowledge about technologies. Here at Linuxgrow, I write about Linux technologies, Aws Cloud, Wordpress blogging and scripting knowledge. You can read more about me at About us page. Thank You :)

You may also like...

Leave a Reply

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

Facebook