[フレーム]
Last Updated: December 11, 2016
·
6.016K
· calsaverini

Check running time of long processes in Linux

To check how many seconds have elapsed since a process started you can use this small shell script:

#!/bin/bash
init=`stat -t /proc/1ドル | awk '{print 14ドル}'`
curr=`date +%s`
seconds=`echo $curr - $init| bc`
name=`cat /proc/1ドル/cmdline`
echo $name $seconds

save it on a file called sincetime and give permissions for your user to run it and put it in your $path. Than, the command:

sincetime <pid>

will return the name of the process with the given pid and its age in seconds.

Also, you can combine it with grep and ps and have this:

#!/bin/bash
pidlist=`ps ax | grep -i -E 1ドル | grep -v grep | awk '{print 1ドル}' | grep -v PID | xargs echo`
for pid in $pidlist; do
 sincetime $pid
done

If you put this in a file called "greptime" with x permission, in your path and blablabla, you can run it like this:

greptime <pattern>

to get all processes whose names match <pattern> (a string or regexp) and their ages in seconds.

1 Response
Add your response

Hi,

Just a note to say thanks, and suggest an improvement...

Using a format specifier in the arguments to stat would make things clearer, rather than relying on the mysterious column 14 of the terse output:

stat /proc/1ドル --printf=%Z

Mark

over 1 year ago ·

AltStyle によって変換されたページ (->オリジナル) /