Q's on Active Process Time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Q's on Active Process Time
# 1  
Old 02-08-2011
Question Q's on Active Process Time

Is it possible to display active processes' Year,Month,Day,Hour,Minute,Second info of process start time ? Preferbly in the format "YYYY/MM/DD HH:MM:SS" ?

I tried to do this with the ps command but it only gets the time or date.

Any help will be greatly appreciated.

Cheers

Steve
# 2  
Old 02-08-2011
Depending on your OS you may be able to use the date command to read the modification time of the /proc/$PID directory:

Code:
date -r /proc/$$ +"%Y/%m%d %T"

On some systems this gives the current time on others the process start time.
# 3  
Old 02-09-2011
Question

Chubler_XL,

Thanks for your info.

I'm using both Solaris 10 and HP-UX B.11.11.

I was able to get the info with your method on Solaris but couldn't on HP-UX because HP-UX does not have "/proc" directory.

Is there a Solaris "/proc" equivalent directory for HP-UX?

Cheers
Steve
# 4  
Old 02-09-2011
On HP-UX you will need to get the process elapsed time and do some maths to calculate it's start date/time:

Code:
ELAPSED=$(UNIX95=1 ps -p $PID -o etime | tail -1)
SECONDS=$(echo $ELAPSED | awk -F"[:-]" ' BEGIN {split("1:60:3600:86400",E) } NF<5 {for(i=NF;i;i--)r+=E[i]*$(NF-i+1);print r;r=0 }')

So your next issue is going to be how to subtract X seconds from today's date and display in the required format.

If you have gnudate you can use:

Code:
date -d "- ${SECONDS} seconds" +"%Y/%m/%d %T"

Otherwise, If you have a C compiler on your HP-UX box you can use my dateadj.c program that will subtract X seconds from the current time and display in any format:

Code:
dateadj "%Y/%m/%d %T" -${SECONDS}


Last edited by Chubler_XL; 02-09-2011 at 08:03 PM.. Reason: Minor typo
# 5  
Old 02-10-2011
MySQL

Thank you Chubler_XL !!!
I was able to achieve what I want it !!!
I didn't know about the UNIX95 command.
Thank you very much for your great support!!!

Cheers
Steve
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Determining if a process is active in UNIX

We have written a bare bones scheduling app using bash scripts. The input to the scheduler is from a mainframe scheduling tool, and the scripts exit code is returned to the MF. The problem is that every now and again I have a script that does not complete and this is left in my Q. I am in the... (1 Reply)
Discussion started by: Charles Swart
1 Replies

2. UNIX for Dummies Questions & Answers

Active sessions open or long time

What kind of problems can be faced if any session which connects to unix server is open for longer time? How to find out from how much time that session is idle? :) (2 Replies)
Discussion started by: anandgodse
2 Replies

3. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

4. Shell Programming and Scripting

determine the active processes on the system which are running since long time

Hi , Please help me shell script to determine the active processes on the system which are running since long time (2 Replies)
Discussion started by: itian2010
2 Replies

5. UNIX for Advanced & Expert Users

Rollover/compress log from ACTIVE process

I have some Solaris processes that run weeks at a time that create rather large log files that I would like to archive/compress daily. Instead of stopping the process, what can be done so that the log file is backed up and shrunk, but the process can still log to the open file handle without major... (7 Replies)
Discussion started by: ckmehta
7 Replies

6. Linux

Process start time not showing correct time

Process start time is not showing the correct time: I had started a process on Jun 17th at 23:30:00. Next day morning when I run the command "ps -ef | grep mq", the process is showing the start date of Jun 17th but the start time is 00:16:41 Day/Date is setup correctly on the server. It... (2 Replies)
Discussion started by: hemangjani
2 Replies

7. UNIX for Advanced & Expert Users

Process accounting and Shell process time

Hi All, I am running the following accounting on one of my executable, $ accton /home/myexe-acct $ ./myexe $ accton When I check the process timings I get the below result, Shell process time: 300ms myexe time: 100ms I want to know on why the shell(sh) process is taking so much time... (1 Reply)
Discussion started by: santoshbr4
1 Replies

8. UNIX for Dummies Questions & Answers

how to Decrease priority of a particular process in time of process creation

how to decrease priority of a particular process in time of process creation... and also how to decrease priority of a particular process after process creation.. can any one please help me out... (2 Replies)
Discussion started by: Ramkum
2 Replies

9. Shell Programming and Scripting

vmstat returns good val for cpuIdle put ps shows no active process

hi i'm running a shell script that checks the amount of cpu idle either using /usr/bin/vmstat 1 2 or sar 1 2 (on unixware) before i run some tests(if cpu idle greater than 89 I run them). These tests are run on many platforms, linux(suse, redhat) hp-ux, unixware, aix, solaris, tru64. ... (5 Replies)
Discussion started by: OFFSIHR
5 Replies
Login or Register to Ask a Question