Skip navigation.
Home
The QNX Community Portal

View topic - how to let hogs run only once,don't update every 3 seconds.

how to let hogs run only once,don't update every 3 seconds.

Isn't the name clear?

how to let hogs run only once,don't update every 3 seconds.

Postby dxwang » Thu Mar 15, 2007 7:54 am

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!
dxwang
Senior Member
 
Posts: 129
Joined: Mon Sep 27, 2004 1:39 pm

RE: how to let hogs run only once,don

Postby mario » Thu Mar 15, 2007 1:33 pm

Not possible, but you could write a script

hogs &
sleep 3
slay hogs
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

Postby dxwang » Fri Mar 16, 2007 1:47 am

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!");
dxwang
Senior Member
 
Posts: 129
Joined: Mon Sep 27, 2004 1:39 pm


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 2 guests