how to check how long the process has been running. | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

how to check how long the process has been running.

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-17-2008
ukatru ukatru is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 6 May 2009, 1:53 AM EDT
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
how to check how long the process has been running.

I have a requirement to check how long a process is running on unix system.If i use ps -ef i am getting the following message

guest 2453638 1998920 0 16:16:05 - 0:00 dsapi_slave 9 8 0

but this is showing only time not the date.Can any one please advice me any script to find out how long this process is running.

Thanks
Sponsored Links
    #2  
Old 08-17-2008
redoubtable redoubtable is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 7 December 2010, 12:28 PM EST
Location: Portugal
Posts: 244
Thanks: 0
Thanked 0 Times in 0 Posts
ps will not help you because it gives you the CPU time. A very simple workaround for this is checking the ctime or mtime of a file created when that process began execution. As such, you can just go ahead and see the date in ls -ld /proc/PID-OF-YOUR-PROCESS.

Example:

Code:
Tsunami comparing # ls -ld /proc/1
dr-xr-xr-x 5 root root 0 2008-08-17 22:21 /proc/1
Tsunami comparing # uptime
 01:11:18 up  2:50,  5 users,  load average: 0.05, 0.06, 0.02
Tsunami comparing # date
Mon Aug 18 01:11:24 WEST 2008
Tsunami comparing #

The creation of init process (PID 1) is more or less when the system started.
Sponsored Links
    #3  
Old 08-17-2008
Annihilannic Annihilannic is offline Forum Advisor  
 
Join Date: May 2008
Last Activity: 28 October 2009, 7:03 PM EDT
Location: Sydney, Australia
Posts: 1,009
Thanks: 0
Thanked 2 Times in 2 Posts
"16:16:05" is the start time of the process, so you can subtract that from the current time to calculate how long it has been running.

When the process is more than 24 hours old, this field will contain a date instead of a time. And if, perchance, the process is more than a year old, it will contain the year.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Monitor a long running process sunpraveen Shell Programming and Scripting 4 05-11-2010 02:46 PM
How to check if process is running? ladyAnne UNIX and Linux Applications 5 05-01-2010 01:20 AM
How to check since when (for how long) a particular process is running ? hpuxlxboy UNIX for Advanced & Expert Users 2 02-19-2009 07:14 AM
check process running rose1207 Shell Programming and Scripting 4 12-28-2007 12:23 AM



All times are GMT -4. The time now is 01:59 AM.