Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Please share command to find any script which is running for more than say 30 minutes. in Linux System

share|improve this question

migrated from stackoverflow.com Jan 15 '13 at 8:50

This question came from our site for professional and enthusiast programmers.

1  
Hi, and welcome to SO. Just so you know, you might consider asking this question at unix.stackexchange.com. Further, this might give you some pointers: linuxcommando.blogspot.com/2008/09/… –  DWright Jan 15 '13 at 8:16
1  
This could be helpful: stackoverflow.com/questions/6134/… –  Prakash Murthy Jan 15 '13 at 8:17

2 Answers 2

the ps command has an etimes field, that gives you the time since a given process has been started, in seconds.

the following bash script will output the PIDs of processes that have been running for longer than 30 minutes.

#!/bin/sh
MIN=30
SEC=$((MIN*60))
ps -eo etimes=,pid= | while read sec pid; do
 if [ ${sec} -gt ${SEC} ]; then
   echo ${pid}
 fi
done
share|improve this answer
    
hi @umlaute, your script gives on my box (standard Ubunut 12.04 setup) a "ERROR: Unknown user-defined format specifier "etimes"". What do I do wrong? –  humanityANDpeace Jan 15 '13 at 10:22
    
ah yes; it seems that only newer versions (>=3.3.0) of procps (actually procps-ng) have the "etimes" field. i'm using debian/wheezy that ships with procps-3.3.3 –  umläute Jan 15 '13 at 11:41

Assuming GNU date + ps, this gives you a list of pids older than 30 minutes:

# weird format to match ps -o lstart
cutoff=$(date -d '30 minutes ago' +'%a %b %e %T %Y')
ps -e -o lstart,pid |
awk '$0 < "'"$cutoff"'" {print NF}'

On linux, you can then check whether /proc/$pid/exe resolves to a known interpreter like /bin/sh, /bin/bash or /usr/bin/python - if so, you know it's a script.

share|improve this answer

Your Answer

 
discard

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