Operating System - HP-UX
1753765 Members
6071 Online
108799 Solutions
New Discussion юеВ

Re: How to find the process started date with year

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

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