0

I'm trying to come up with command using AWK which will list down all the processes along with its number of instances running:

I'm using following command

ps axo pid,command  | awk -F/ '{print $1, $4}'

and I;m getting following result

 1727  sshd
 1807  httpd
 1834  abrtd
 1842 abrt-dump-oops -d  abrt -rwx
 1848  httpd
 1849  httpd
 1879  gpm -m

I want to above command so that it can display total number of process count along with the process, something as follows

 1   1727  sshd
 3   1807  httpd
 1   1834  abrtd
 1   1842 abrt-dump-oops -d  abrt -rwx
 1   1879  gpm -m

In fact I want to kill a process running more than 5 instances does not matter what process it is.

tshepang
  • 12,111
  • 21
  • 91
  • 136
user1405309
  • 397
  • 1
  • 4
  • 11

2 Answers2

0

This is not awk but it should produce the output you want.

ps axo pid,command | sort -k2 | uniq -c -f 1
Vivek
  • 2,000
  • 3
  • 16
  • 22
-1

try this .....

ps -eo command | grep -v COMMAND | awk '{count[$0]++}END{for(j in count) print count[j] ,j}' | sort -rn | head