1748182 Members
3560 Online
108759 Solutions
New Discussion юеВ

Re: Process Information

 
SOLVED
Go to solution
G V R Shankar
Valued Contributor

Process Information

Hi All,

Is there a way to know the process start time after 24 hours?

After 24 hours, it starts showing the date instead of time.

Thank you.

Ravi
19 REPLIES 19
Steven Schweda
Honored Contributor

Re: Process Information

> After 24 hours, it starts showing the date
> instead of time.

What is this "it"?

As usual, showing actual commands with their
actual output can be more helpful than vague
descriptions and interpretations.

"uname -a" would be a good place to start,
too.
Dennis Handly
Acclaimed Contributor
Solution

Re: Process Information

I assume you are talking about ps(1)?
I don't see any evidence of how to get more details. Except by rolling your own with pstat_getproc(2)?
Laurent Menase
Honored Contributor

Re: Process Information

UNIX95= ps -o pid,comm,etime

etime gives the time in day-h:m:s
else pstat_getproc() in a c program
G V R Shankar
Valued Contributor

Re: Process Information

Could you please share a script that can give me the process start time using the elapsed time?

Thank you very much.

Ravi.
Laurent Menase
Honored Contributor

Re: Process Information

I use C
#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);
}

cc etimetodate.c -o etimetodate
etimetodate 2-02:01:01
G V R Shankar
Valued Contributor

Re: Process Information

Hi,

I have created a user with c shell and run the script as mentioned.

I am receiving the following error.

Warning 942: "etimetodate.c", line 12 # Types 'long *' and 'int *' are not assignment-compatible.
time(&t);
^
Warning 942: "etimetodate.c", line 27 # Types 'const long *' and 'int *' are not assignment-compatible.
strftime(buf,256,"%y/%m/%d %H:%M:%S",localtime(&t));

Could you please help me? I am not good a C.

Ravi.
Laurent Menase
Honored Contributor

Re: Process Information

it is not important,
since we compile in 32bits mode, long and int are compatible.

if you want to avoid them just replace
int t;
by
long t;

Happy new year
Dennis Handly
Acclaimed Contributor

Re: Process Information

>I have created a user with C shell and run the script as mentioned.

Why would you want to use the scummy C shell? Also this is a C program, not a script.

>Laurent: It is not important, since we compile in 32bits mode, long and int are compatible.

It is better to be correct in all modes.

>if you want to avoid them just replace

The correct typedef is time_t, not int nor long. See time(2).

>time(&t);

A faster version that doesn't make the kernel sweat is:
t = time(NULL);

>char buf[255];
>strftime(buf, 256, "%y/%m/%d %H:%M:%S", localtime(&t));

Instead of getting the sizes wrong, you should use sizeof, provided buf isn't a parm:
strftime(buf, sizeof(buf), "%y/%m/%d %H:%M:%S", localtime(&t));

>#include

Note: The correct ANSI C header is .
G V R Shankar
Valued Contributor

Re: Process Information

Hi Laurent,

I have modified int t to long t. It works.

The new program looks like following, please correct me if I am wrong.

#include
#include
char *sep="::-x"; int coefs[]={1,60,3600,3600*24,0};
main(c,v)
int c;
char **v;
{
long 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);
}

Thank you very much.

Hi Dennis,

I have modifed the script to the following. This also works. Any other suggestions.

#include
#include
char *sep="::-x"; int coefs[]={1,60,3600,3600*24,0};
main(c,v)
int c;
char **v;
{
time_t t;
char buf[255];
int dt=0;
int icoef=0;
t = time(NULL);
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, sizeof(buf), "%y/%m/%d %H:%M:%S", localtime(&t));
printf("%s\n",buf);
}