Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-06-2008, 11:11 AM   #1
Registered: Feb 2006
Distribution: Gentoo, Slackware, Debian, Suse
Posts: 86

Rep: Reputation: 15
bash calculate job duration

I need to know how long the particular job is running on my system

The approach to get

start_time=`ps -ef | grep <job_name> | awk '{print $3}'  `
and then substitute from
date today
the $start_time works well until the job started for example, at 23:58 and the script that checks it duration every 10 minutes will run at 00:05 - in this case ps -ef will return the date instead of time and I cannot make accurate calculations.

Any ideas or solutions?
Old 10-06-2008, 11:17 AM   #2
Senior Member
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
What about this:
time command
Old 10-07-2008, 03:33 AM   #3
Registered: Feb 2006
Distribution: Gentoo, Slackware, Debian, Suse
Posts: 86

Original Poster
Rep: Reputation: 15
No, for this I need to start a certain process in "time" command. But the process is started as a child from another script and I cannot modify it.

I found better solution

[CODE]ps -eo pid,etime,comm[CODE]

it gives me just what I need


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl/bash - calculate date in future rose_bud4201 Programming 6 05-10-2009 06:59 AM
Bash script not running within crontab job WrightExposure Linux - General 3 01-23-2007 07:28 PM
Bash Script, calculate output. eldaria Programming 13 07-20-2006 10:26 PM
Bash script and cron job rust8y Linux - General 2 07-08-2006 08:45 AM
Move a job from one bash shell to another? marktaff Linux - General 3 01-13-2006 08:22 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:26 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration