1

My top looks like this:

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND          
 6524 asjzdiwq  30  10  500m  41m  24m S  0.0  0.3   0:15.27 php-cgi      
21274 asjzdiwq  30  10  500m  41m  24m S  0.0  0.3   0:04.97 php-cgi      
 9047 asjzdiwq  30  10  500m  40m  24m S  0.0  0.3   0:13.72 php-cgi      
26918 asjzdiwq  30  10  499m  40m  24m S  0.0  0.3   0:12.87 php-cgi      
13168 ahfvw0d1  30  10  498m  35m  20m S  0.0  0.2   0:03.49 php-cgi      
 8859 realnoni  30  10  495m  33m  20m S  0.0  0.2   0:11.27 php-cgi      
 6590 asjzdiwq  30  10  495m  32m  20m S  0.0  0.2   0:13.34 php-cgi      
 5657 holeyrai  30  10  495m  31m  19m S  0.0  0.2   0:04.47 php-cgi      
14480 ripplecr  30  10  498m  31m  17m S  0.0  0.2   0:02.90 php-cgi      
14442 ripplecr  30  10  497m  31m  17m S  0.0  0.2   0:02.00 php-cgi      
10720 computer  30  10  496m  31m  18m S  0.0  0.2   0:08.75 php-cgi      
23821 loghome   30  10  496m  31m  18m S  0.0  0.2   0:02.22 php-cgi      
17623 devilsti  30  10  495m  31m  19m S  0.0  0.2   0:05.81 php-cgi      
13305 realnoni  30  10  495m  30m  18m S  0.0  0.2   0:06.29 php-cgi      
14461 ripplecr  30  10  496m  30m  17m S  0.0  0.2   0:01.47 php-cgi           
 8738 holeyrai  30  10  495m  30m  18m S  0.0  0.2   0:03.37 php-cgi      
17569 devilsti  30  10  495m  30m  18m S  0.0  0.2   0:05.73 php-cgi      
13174 ahfvw0d1  30  10  484m  30m  18m S  0.0  0.2   0:04.00 php-cgi      
16126 realnoni  30  10  484m  30m  18m S  0.0  0.2   0:12.08 php-cgi      
31561 a0w4pkbp  30  10  496m  30m  17m S  0.0  0.2   0:03.54 php-cgi      
31565 ahfvw0d1  30  10  484m  29m  17m S  0.0  0.2   0:05.80 php-cgi      
21275 asjzdiwq  30  10  484m  29m  18m S  0.0  0.2   0:01.77 php-cgi      

You can see that the same "USER" can have multiple "COMMAND"s running as "php-cgi". I would like to find out which user is running the most processes and get a count of how many processes they are running.

1

To count all processes per user:

ps -eo user|sort|uniq -c|sort -n

or to just have the ones running php-cgi:

ps -eo user:15,cmd|sed -n '/php-cgi/s/ .*//p'|sort|uniq -c|sort -n
  • Thanks - the first command works well and displays the full usernames! The second command works correctly, but it displays most of the USERS with UID and not the full usernames. – Dave K Oct 8 '15 at 19:47
  • I think it is because your usernames are longer than the default width of the field. Try giving an explicit width ps -eo user:15,cmd|.... I've edited this into my answer. – meuh Oct 8 '15 at 19:58
  • Setting it to 15 made most of the usernames appear, but 20 made them all appear - thanks! – Dave K Oct 8 '15 at 20:32
0

Use ps. From man ps:

-U userlist
Select by real user ID (RUID) or name. It selects the processes whose real user name or ID is in the userlist list. The real user ID identifies the user who created the process, see getuid(2).

-u userlist
Select by effective user ID (EUID) or name. This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)). Identical to U and --user.

So for example to see all processes of user asjzdiwq, you can use:

ps -u asjzdiwq  ## Using RUID
ps -U asjzdiwq  ## Using EUID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.