LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-10-2004, 03:08 AM   #1
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Rep: Reputation: 15
how get a process run time


hi,all
i know use ps -aux can get a process's start time, but how get a process the time from the process start to now? thanks
 
Old 06-10-2004, 03:40 AM   #2
Qucho
Member
 
Registered: Mar 2004
Location: Colorado, US
Distribution: Debian "Sarge"
Posts: 228

Rep: Reputation: 30
You mean as in ... For how long it has been running ??
Try:
~$ top
 
Old 06-10-2004, 03:56 AM   #3
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Qucho
You mean as in ... For how long it has been running ??
Try:
~$ top
yes
thanks ,but top cant use shell script , because i wannt get the time to a variable in bash shell script.
 
Old 06-10-2004, 03:39 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
If you know the current time and the start time, you can calculate the difference.
 
Old 06-10-2004, 08:14 PM   #5
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
i know, but if i use ps -aux , i only get the time ,but i cant get date,
 
Old 06-10-2004, 08:53 PM   #6
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Why not just use the date command then? Store the output of date in a variable before the command is executed. Store the output of date after the command runs, and then parse & subtract the do variables.
Code:
prog_start_time=`date`
execute some_program
prog_stop_time=`date`

process difference between prog_stop_time and prog_start_time
 
Old 06-10-2004, 11:08 PM   #7
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Dark_Helmet
Why not just use the date command then? Store the output of date in a variable before the command is executed. Store the output of date after the command runs, and then parse & subtract the do variables.
Code:
prog_start_time=`date`
execute some_program
prog_stop_time=`date`

process difference between prog_stop_time and prog_start_time
THANKS,but it must wait the program stoped,and i want take the just running program 's use time, if the time is over but the program is running now,i will kill it
 
Old 06-10-2004, 11:36 PM   #8
Qucho
Member
 
Registered: Mar 2004
Location: Colorado, US
Distribution: Debian "Sarge"
Posts: 228

Rep: Reputation: 30
Quote:
THANKS,but it must wait the program stoped,and i want take the just running program 's use time, if the time is over but the program is running now,i will kill it
start_time = your_code_used _to_get_this(ps -aux)
current_time = hwclock
time_quota = set-your-limit
calcultate running_time by extracting start_time to current_time
if running_time > time_quota then kill
 
Old 06-10-2004, 11:38 PM   #9
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
Ok, so when you launch the program, either have it "touch" a file, or echo the date as contents of some temporary file.
Code:
echo `date` > /var/tmp/prog_start_time
execute some_prog

Then, in whatever script you want to analyze the program's running time:
Code:
prog_start_time=`cat /var/tmp/prog_start_time`
current_time=`date`

process difference between prog_start_time and current_time
 
Old 06-10-2004, 11:45 PM   #10
henryluo
Member
 
Registered: Nov 2003
Posts: 36

Original Poster
Rep: Reputation: 15
thanks very much ,
that a good idea, if i cant find some command have this fuction, i will try it ,


thanks again
 
  


Reply


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
Killing a process after x amount of time... virid Linux - Newbie 3 03-17-2006 07:13 AM
Incorrect process start time hulala Fedora 2 04-26-2005 10:36 PM
Booting process takes long time. benoy4007 Red Hat 8 06-13-2004 12:35 PM
Time of a process? AquamaN Programming 1 09-22-2003 03:46 AM
killing process at time limit hfawzy Linux - General 0 05-31-2003 04:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 AM.

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