Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to know which processes are running more than 6 hours in UNIX. How can I find those out?

share|improve this question

migrated from serverfault.com Sep 13 '13 at 19:42

This question came from our site for system and network administrators.

Care to share what flavor of unix this is? – EEAA Sep 12 '13 at 19:15
Most versions of ps aux show the column START with the start time or date. – ott-- Sep 12 '13 at 20:17
If you are looking to limit CPU time per process, look at pam_limits. – 200_success Sep 12 '13 at 21:42

Depending on what you have available the general approach might be:

ps -o pid,lstart

and run a for loop over the results using something like:

date -j -f %c "$sdate" +%s

to convert the date to a UNIX timestamp. From there something like:

time=$((`date +%s`-`date -j -f %c "$sdate" +%s`))
echo $time

should give you the number of seconds that the process has been running. converting to hours is then trivial.

The short and long is that you will end up writing a script.

share|improve this answer

You can use following function to Get Process elapse time in minutes

GetProcTime() {
    local p=$1
    ps -eao "%C %U %c %t" | 
    awk "/$p/"'{print $4}' | 
    awk -F":" '{{a=$1*60} {b=a+$2}; if ( NF != 2 ) print b ; else print $1 }'


root@ubuntu:/tmp# GetProcTime monit
root@ubuntu:/tmp# if [[ $(GetProcTime monit) -ge 360 ]]; then echo "Process is running more than 6 hrs"; else echo "OK"; fi
root@ubuntu:/tmp# GetProcTime init
root@ubuntu:/tmp# if [[ $(GetProcTime init) -ge 360 ]]; then echo "Process is running more than 6 hrs"; else echo "OK"; fi
Process is running more than 6 hrs
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.