- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Process Information
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2009 10:39 PM
12-22-2009 10:39 PM
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
Solved! Go to Solution.
- Tags:
- PS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2009 12:12 AM
12-23-2009 12:12 AM
Re: Process Information
> 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2009 02:03 AM
- Tags:
- pstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2009 04:36 AM
12-23-2009 04:36 AM
Re: Process Information
etime gives the time in day-h:m:s
else pstat_getproc() in a c program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2009 01:32 AM
12-30-2009 01:32 AM
Re: Process Information
Thank you very much.
Ravi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2009 03:51 PM
12-30-2009 03:51 PM
Re: Process Information
#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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2009 03:28 AM
12-31-2009 03:28 AM
Re: Process Information
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.
- Tags:
- csh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2009 07:15 AM
12-31-2009 07:15 AM
Re: Process Information
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2009 08:14 AM
12-31-2009 08:14 AM
Re: Process Information
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
- Tags:
- scummy C shell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2010 08:17 AM
01-01-2010 08:17 AM
Re: Process Information
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2010 08:27 AM
01-01-2010 08:27 AM
Re: Process Information
Forgot to mention. I wish you and your beloved ones a very happy and prosperous new year 2010.
Thank you.
Ravi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2010 12:53 PM
01-01-2010 12:53 PM
Re: Process Information
You could use Perl. In fact, instead of manually running 'ps' you could use this script:
# cat ./ps_etimes
#!/usr/bin/perl
#@(#) Show processes with elapsed time as a start timestamp - JRF
use strict;
use warnings;
use POSIX qw(strftime);
my @weights = ( 1, 60, 3600, 86400 );
my $now = time();
$ENV{UNIX95} = 1;
open my $fh, 'ps -eo pid,comm,etime|' or die "Can't fork: $!\n";
while (<$fh>) {
next if $. == 1;
chomp;
my ( $pid, $comm, $etime ) = split;
my @a = reverse split /[:-]/, $etime;
my $t = 0;
for ( 0 .. @a - 1 ) {
$t += $a[$_] * $weights[$_];
}
printf "%5d %-15s %s\n", $pid, $comm,
strftime( "%Y/%m/%d %H:%M:%S", localtime( $now - $t ) );
}
1;
The output is a process list as if you had done:
# UNIX95= ps -eo pid,comm,etime
...except the header line is suppressed and the 'etime' field is computed to the process instantiation timestamp instead of the elapsed 'd-h:m:s' format it normally takes.
Simply run as:
# ./ps_etimes
...or for a particular process (for example):
# ./ps_etimes | grep diaglogd
Regards (and Happy New Year)!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2010 12:07 AM
01-02-2010 12:07 AM
Re: Process Information
The perl script works like a charm.
Thank you very much.
Hi Laurent and Dennis,
Thank you very much for the C programs.
Cheers,
Ravi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2010 08:17 AM
01-02-2010 08:17 AM
Re: Process Information
Cheers,
Ravi.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2010 08:32 AM
01-02-2010 08:32 AM
Re: Process Information
... except the header line is suppressed
If you want to suppress the header line, why don't you use this instead:
UNIX95=EXTENDED_PS ps -e -opid= -ocomm= -oetime=
(And remove: next if $. == 1;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2010 08:56 AM
01-02-2010 08:56 AM
Re: Process Information
> Dennis: If you want to suppress the header line, why don't you use this instead:
UNIX95=EXTENDED_PS ps -e -opid= -ocomm= -oetime=
(And remove: next if $. == 1;)
I certainly could have, but chose to skip the first line to keep the command easier to ammend. Of course in doing so, I sacrificed a few extra CPU cycles :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2010 01:48 AM
01-04-2010 01:48 AM
Re: Process Information
>
>It is better to be correct in all modes.
yes, I agree for a long program, but what I mean is that it doesn't change the result
>>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);
Indeed you avoid the copyout of a long
which for a repetitive program run could have side effect
>>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));
Yes; indeed it is much better and due to quick and dirty copy/past. ( at least a 256 would have been better even if in that case,it will have no side effect since the format output is much smaller than the 256 bytes)
>>#include
>Note: The correct ANSI C header is
yes, it is old habits, like the old style main declaration,
main(c,v)
int c;
char **v;
the new way is main(int c,char *v[])
you could also tell that #include
I could also have included the call to pstat_getproc() in the program
#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);
}
- Tags:
- bad html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2010 07:57 PM
01-04-2010 07:57 PM
Re: Process Information
#include
#include
#include
int main(int argc, char **argv) {
int i;
time_t t, t2;
int dt;
struct tm tm1;
char buf[255];
t = time(NULL);
for (i = 1; i < argc; ++i) {
// use %j to collect days
char *result = strptime(argv[i], "%j-%H:%M:%S", &tm1);
if (result) {
if (*result != '\0')
printf("strptime bad result: %s\n", result);
} else {
printf("strptime error\n");
}
dt = ((((tm1.tm_yday + 1) * 24 + tm1.tm_hour) * 60) + tm1.tm_min) * 60 +
tm1.tm_sec;
t2 = t - dt;
strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", localtime(&t2));
printf("%s\n",buf);
}
return 0;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2010 05:07 AM
01-05-2010 05:07 AM
Re: Process Information
#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);
}
no need for ps anymore
./a.out pid will give the start date for the given process.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2010 09:23 AM
01-05-2010 09:23 AM
Re: Process Information
Yes, I noticed that, though the tool may want to take more than one PID.