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

Depending on your OS you may be able to use the date command to read the modification time of the /proc/$PID directory:

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

On some systems this gives the current time on others the process start time.

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

On HP-UX you will need to get the process elapsed time and do some maths to calculate it's start date/time:

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*$(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:

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:

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

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