Find all pid of "httpd" where process state is "Ss" only and process is 1 day old

We can use etime format that comes with PS command .
This option shows the elapsed time since the process was started, in the the form: [[dd-]hh:]mm:ss</p>

Now grep the output for finding processes with Status Ss and finally you can use AWK/Grep to list all those are older than 1 day. ( means all output those contains "-" in the out put.

A step wise output would be

[juned@nagios ~]$ ps -A -o pid,user,comm,stat,etime
  PID USER     COMMAND          STAT     ELAPSED
    1 root     init             S     6-12:06:50
    2 root     ksoftirqd/0      SN    6-12:06:50
    3 root     events/0         S<    6-12:06:50
    4 root     khelper          S<    6-12:06:50
31395 root     smbd             S     3-05:44:26
32472 apache   httpd            S     2-05:06:13
 2133 root     sshd             Ss      04:03:31
 2135 juned    sshd             S       04:03:28
 2136 juned    bash             Ss      04:03:28
 2426 apache   httpd            S          48:18
 2428 apache   httpd            S          48:17
 2429 apache   httpd            S          48:17
 2430 apache   httpd            S          48:17
 2431 apache   httpd            S          48:17
 2721 juned    ps               R+         00:00

[juned@nagios ~]$ ps -A -o pid,user,comm,stat,etime | grep  httpd
 2356 root     httpd            Ss    6-12:05:39
 2370 apache   httpd            S     6-12:05:38
 2371 apache   httpd            S     6-12:05:38
 2373 apache   httpd            S     6-12:05:38
 2374 apache   httpd            S     6-12:05:38
32472 apache   httpd            S     2-05:06:35
 2426 apache   httpd            S          48:40
 2428 apache   httpd            S          48:39
 2429 apache   httpd            S          48:39
 2430 apache   httpd            S          48:39
 2431 apache   httpd            S          48:39

[juned@nagios ~]$ ps -A -o pid,user,comm,stat,etime | grep Ss |grep  httpd
 2356 root     httpd            Ss    6-12:09:57

[juned@nagios ~]$ ps -A -o pid,user,comm,stat,etime | grep Ss |grep  httpd   | awk ' /-/ { print  $1 }'
2356 </p>

Other way will be :

ps aux  | grep -w 'Ss' | grep httpd | awk '{print $9,$2}' | sort -t: +1 -9 | grep -v : </div>

comments powered by Disqus