Operating System - Linux
1822909 Members
3921 Online
109645 Solutions
New Discussion

Re: Determining the elapsed time for a process - etime

 
Adam Noble
Super Advisor

Determining the elapsed time for a process - etime

I am trying to write a very simply script taht simply check if a process has been running for more than an hour and then kills it. With the complications of the 24 hour clock I was hoping there was a simply ps option that simply gave me elapsed time. In the man page there does appear to be an option of etime, however I am unable to get this to work has anyone got any ideas.
1 REPLY 1
Stuart Browne
Honored Contributor

Re: Determining the elapsed time for a process - etime

ps -eo etime=,pid= | awk -F':' '{if (NF > 2) { system( "kill -TERM " $2 )}'

... a bit indiscriminate ... You might want to do checks for a given process etc. etc., but, that's the basics.

Hope it helps!

NOTE: The 'ps' man page gives you lots of options of how you want the output of PS to look. Using the '-o' operator, you supply a comma-separated list of the fields you want. Using the '=' after it means "don't print the title of this field"
One long-haired git at your service...