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


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.

ps -eo etimes=,pid= | while read sec pid; do
 if [ ${sec} -gt ${SEC} ]; then
   echo ${pid}
  • 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? Jan 15, 2013 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, 2013 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.

You must log in to answer this question.