OpenQNX :: The QNX Community Portal

Jul 19, 2008 - 03:33 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 36 unlogged users and 0 registered users online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
dxwang
Post subject: how to let hogs run only once,don't update every 3 seconds.  PostPosted: 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!
 
 View user's profile Send private message  
Reply with quote Back to top
mario
Post subject: RE: how to let hogs run only once,don  PostPosted: 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
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
dxwang
Post subject:   PostPosted: 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!");
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.