System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to find the process started date with year

 
SOLVED
Go to solution
senthil_kumar_1
Super Advisor

How to find the process started date with year

Hi All,

I am not able to see the started the date (with date and year) of the process using the command "ps -ef | more".

For example:

#ps -ef | more
UID PID PPID C STIME TTY TIME COMMAND
root 0 0 0 Nov 12 ? 3:34 swapper
root 1 0 0 Nov 12 ? 19:36 init
root 2 0 0 Nov 12 ? 1954:12 vhand
root 3 0 1 Nov 12 ? 1585:25 statdaemon


In above command, it is showing only month and date under STIME (start time) but not year.

I want to view the date with year.

Is it possible?

How to see that?
15 REPLIES
Jeeshan
Honored Contributor

Re: How to find the process started date with year

STIME is the process start time
a warrior never quits
Pete Randall
Outstanding Contributor

Re: How to find the process started date with year

A little logic might help. If you run the "uptime" command and do a little math, you can figure this out. My first guess would be 2009, but if uptime indicates you've been up longer than 450 or so days, it must be 2008.


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: How to find the process started date with year

Hi Senthil:

> In above command, it is showing only month and date under STIME (start time) but not year. I want to view the date with year.

The manpages suggest that you will have to filter the output to reformat things. I'm not sure why you want the year displayed.

You might map the month name to its ordinal value. Compare that value to the current month ordinal. If the first value is greater than the current month, then the year is year-1. In your example, Nov(ember) [11] is greater than Apr(il) [4], so we might assume that the process started in 2010-1 or 2009.

Again, why do you care?

Regards!

...JRF...
Robert Salter
Respected Contributor

Re: How to find the process started date with year

The processes you list are usually started at boot up. Check the /etc/shutdownlog or /etc/rc.log files, they'll show you the year. Maybe there's a pid file in /var/run or somewhere that an app would put it.

If it's an app process that has a mmmdd for STIME, based on the last time the server was booted you could get a good idea of the year when the app process started.

Other than that the man page for ps states that after 24 hours,the starting date for a process is displayed, obviously without the year.

beers,

robert
Time to smoke and joke
Raj D.
Honored Contributor

Re: How to find the process started date with year

Senthil,

These are primary process and starts during system startup,
root 0 0 0 Nov 12 ? 3:34 swapper
root 1 0 0 Nov 12 ? 19:36 init
root 2 0 0 Nov 12 ? 1954:12 vhand

Use uptime to determine the process start time, [ Current date - server uptime date ]
# uptime


You can try:
# UNIX95=1 ps -e -o pid,ppid,time,etime,args | more

etime will show the : Elapsed time of the processes. under the field ELAPSED.


Hth,
Raj.


" If u think u can , If u think u cannot , - You are always Right . "
Solution

Re: How to find the process started date with year

>I want to view the date with year.

This thread wanted to know the start time in minutes and seconds. I assume adding the year is trivial.
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1395780
Suraj K Sankari
Honored Contributor

Re: How to find the process started date with year

Hi,
>>want to view the date with year.
I dont think so we can see the year

>>Is it possible?
yes for time its possible

>>How to see that?
I am using this below command
UNIX95= ps -e -o time,etime,pid,ppid,args

Suraj
S-M-S
Valued Contributor

Re: How to find the process started date with year

Hi Senthil,

Better you compare the ps -ef out put and the uptime (TIME )in "top" utility for same PID
DeafFrog
Valued Contributor

Re: How to find the process started date with year

Hello to All ,

Raj : "etime will show the : Elapsed time of the processes. under the field ELAPSED"

for many process it shows as "122-04:20:13" , how to comprehend that ?

Regards ,
FrogIsDeaf

Re: How to find the process started date with year

>DeafFrog: it shows as "122-04:20:13", how to comprehend that?

I assume it is the same format as time, ps(1):
The TIME column format changes from mmmm:ss to [dd-]hh:mm:ss.
Laurent Menase
Honored Contributor

Re: How to find the process started date with year

Laurent Menase
Honored Contributor

Re: How to find the process started date with year

#include
#include
#include
main(int c,char *v[])
{
struct pst_status pst;
long t;
int pid;
char buf[256];
pid=atoi(v[1]);
if(pstat_getproc( &pst,sizeof(pst), 0 , pid)<0)
{
perror("pstat");
exit(0);
}
t=pst.pst_start;
strftime(buf,sizeof(buf),"%y/%m/%d %H:%M:%S",localtime(&t));
printf("%s\n",buf);
}
give the start date from pid
Laurent Menase
Honored Contributor

Re: How to find the process started date with year

#include
#include
#include
main(int c,char *v[])
{
struct pst_status pst;
long t;
int pid;
char buf[256];
pid=atoi(v[1]);
if(pstat_getproc( &pst,sizeof(pst), 0 , pid)<0)
{
perror("pstat");
exit(0);
}
t=pst.pst_start;
strftime(buf,sizeof(buf),"%Y/%m/%d %H:%M:%S",localtime(&t));
printf("%d %s %s\n",pst.pst_pid,buf,pst.pst_ucomm);
}

# cc ps2.c -o ps2
# ps2 1
1 2010/04/16 16:24:09 init
Raj D.
Honored Contributor

Re: How to find the process started date with year

DeafFrog,


>or many process it shows as "122-04:20:13" , how to comprehend that ?

In that case the elapsed time would be in the same format as Dennis mentioned, and it would represent:

122 days, 4 hours , 20 Minute and 13 seconds.

Thanks for bringing in the example..

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Laurent Menase
Honored Contributor

Re: How to find the process started date with year

#include
#include
char *sep="::-x"; int coefs[]={1,60,3600,3600*24,0};
main(c,v)
int c;
char **v;
{
int t;
char buf[255];
int dt=0;
int icoef=0;
time(&t);
while (*sep)
{
char *r;
char *p=strrchr(v[1],*sep++);
r=v[1];
if (p!=NULL )
{
*p=0;
r=p+1;
}
dt=dt+atoi(r) *(coefs[icoef++]);
*r=0;
}
t-=dt;
strftime(buf,256,"%y/%m/%d %H:%M:%S",localtime(&t));
printf("%s\n",buf);
}
convert days-H:M:S to y/m/d H:M:S