| Author |
Message |
|
|
Post subject: how to let hogs run only once,don't update every 3 seconds.
Posted: Mar 15, 2007 - 07:54 AM
|
|
Senior Member
Joined: Sep 27, 2004
Posts: 129
|
|
hi,everyone!
I want to let hogs run only once, just to see the current state , don't want to see it update every 3 seconds. I have looked the options about hogs, but have no idea. Thanks! |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: how to let hogs run only once,don
Posted: Mar 15, 2007 - 01:33 PM
|
|
QNX Master
Joined: Sep 01, 2002
Posts: 2773
|
|
Not possible, but you could write a script
hogs &
sleep 3
slay hogs |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Mar 16, 2007 - 01:47 AM
|
|
Senior Member
Joined: Sep 27, 2004
Posts: 129
|
|
I want to print the percent of cpu for idle process in my c program.
1) if pclose(ptr) is used (this means I just want hogs run only once). the program can't print the message I want, just print the message about the broken pipe. (if use fd , the program run correctly. I know this problem occurs because hogs update message every 3 seconds . but I just want to print message only once.)
2) if pclose(ptr) isn't used (this means print the message all the time ) , the program can't print the message immediately. I have tried fflush(stdout) and setvbuf为_IONBF,but still can't solve it .
I don't know how to slove this two programs. Thanks.
char *cmd = "hogs | awk '{if($1==1)print$4}'";
// char *cmd = "hogs | awk '{print$4}'";
char buf [10];
FILE *ptr;
short idlecpu;
if ((ptr = popen(cmd, "r")) != NULL)
if(fgets(buf,10, ptr) != NULL)
{
if(fgets(buf,10, ptr) != NULL)
idlecpu=atoi(buf);
printf("idlecpu=%d \n",idlecpu);
printf("%s ",buf);
}
pclose(ptr);
printf("exit!"); |
|
|
| |
|
|
|
 |
|
|
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group Credits |
|
|