Unix Technical Forum

Need help in PS command for AIX

This is a discussion on Need help in PS command for AIX within the AIX Operating System forums, part of the Unix Operating Systems category; --> Hi The command in AIX (ps -o "start") would give the output in the following format, ps -u dsaudit ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 08:47 AM
ramu_av_82@yahoo.com
 
Posts: n/a
Default Need help in PS command for AIX

Hi

The command in AIX (ps -o "start") would give the output in the
following format,

ps -u dsaudit -o start
STARTED
Feb 01
12:32:04
12:32:00
time the command started. If the process was started less than 24 hours
ago, the output format is " HH:MM", else it is "mmm dd" (where mmm is
the three letters of the month).


But when the same Mac OSx (ps -o lstart) gives the output in the
following format.
STARTED
Thu Feb 9 22:44:12 2006
Tue Feb 14 17:51:45 2006
Thu Feb 9 14:21:16 2006
Thu Feb 9 14:21:17 2006

Is there a way to get the start time in the long format in AIX
machines.

Please let me know as early as possible. Thanks in advance.

Thanks,
Ramu Anekere

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-05-2008, 08:47 AM
sllabres
 
Posts: n/a
Default Re: Need help in PS command for AIX

Hello.

Tried 'ps -o etime'?
Format is still different from what you want / get on Mac, but it gives
you at least the full difference ( [[ dd-]hh:]mm:ss )

Don't now if there are LANG environment tricks to get the full time.
Maybe this quick hack might help

ps -ef -o etime,args | perl -ne '
{ if ($_=~/(??\d*)\-)?(\d{2})?(\d{2})\d{2}) (.*)$/) {
printf("%s %s\n",
scalar(localtime(time-(($1*86400)+($2*3600)+($3*60)+$4))),$5)
} }'


Bye, Stefan ... . .

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-05-2008, 08:48 AM
ramu_anekere
 
Posts: n/a
Default Re: Need help in PS command for AIX

Thanks a lot for the solution Stefan,

But from the above method the process start time sometimes may change.
I ran the above chunk of code for a while in a loop ad I got the value
differing by one minute.

For me the Process start time remaining constant is very important
factor. Can you please suggest me some other method.

Thanks ageain.
Ramu Anekere

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2008, 08:48 AM
sllabres
 
Posts: n/a
Default Re: Need help in PS command for AIX

Hello Ramu

Are you sure that the difference is (exactly?) a minute and
not a _second_?
The reason for a short difference is that the perl script
uses the difference from the current time and the process
elapsed time to calculate the process start time.
As there is a small amount of time between the output of the
ps command and the start of the script there might be a difference.
(But if you aren't running a RS/6000 250 with 20.000 processes
it should not take a minute ;-)

You might be able do reduce the effect for a large process table
by getting the current time in advance. But the problem will
not vanish entirely:

perl -e '
$T=time; printf("T=%s\n",$T);
open(PS,"/usr/bin/ps -eo etime,args|") || die "PS FAILED";
while (defined($L=<PS>)) {
if ($L=~/(??\d*)\-)?(\d{2})?(\d{2})\d{2}) (.*)$/) {
print localtime($T-(($1*86400)+($2*3600)+($3*60)+$4)).
" ".$5."\n";
}
}
close(PS); '

If you are depended that the start time does not change between
subsequent calls you can

o Run ps -eo etime,args 'raw', test if start time has changed.
(Don't know how that should happen btw.) If everything is all right
continue and convert the time afterwards.
o Convince IBM that you need something like 'ps -eo lstart'
(If it's not already hidden somewhere).
o Help you with the following small C code

#include <procinfo.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>

extern int errno;
#define TSZ 64

int main()
{
struct procsinfo pbuf[TSZ];
char *stime;
pid_t iptr;
int i,j;

iptr=(pid_t) 0;
while ( (i=getprocs(&pbuf,sizeof(struct procsinfo),
0,0,&iptr,TSZ)) > 0 ) {
for (j=0;j<i;j++) {
stime=ctime((const time_t*) &pbuf[j].pi_start);
stime[strlen(stime)-1]='\0';
printf("%s %s\n", stime, pbuf[j].pi_comm);
}
}

if (i==-1)
printf("ERROR: %d (%s)\n",errno,strerror(errno));

return i;
}

Greetings to India
Bye, Stefan ... . .

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:58 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com