CPU occupy rate

in my programme a, I use spawnl(NO_WAIT,“b”,“b”,NULL) to start proc b,
in b I use spawnl(NO_WAIT,"/bin/ls","/bin/ls","/net/myhost",NULL); to check if QNET is ok every 5 second,the code is below.
while(1)
{
sleep(5);
spawnl(NO_WAIT,"/bin/ls","/bin/ls","/net/myhost",NULL);
}

but I found that the CPU occupy rate rises slowly until it is 100%,Is my way
error?please help me

Try system("/bin/waitfor /net/myhost 5");

Why don’t you just open("/net/myhost" ) instead. Much less costly then doing a spawnl.

As for why it goes to 100% CPU, I don’t know. Is it your process that uses 100%?

You mean, stat don’t you Mario? You don’t want a connection to it.

;)

indeed,I need to save the date to remote computer by qnet, I should make the qnet ok,now I use “ls /net/myhost” every 5 sec to do it,mario,Do you have better way?:).by the way,I found qnet is
not stable,if I disconnect the line and connect it again,although I can use “ls /net/myhost” to find the computer again,but the speed of tranfering decreases a lot.What should I do ?

What version of QNX are you using. Qnet prior to version 6.3 wasn’t very stable.

As for suggesting a “better way”, I’m not sure exaclty what you are trying to acheive so I can’t really make a suggestion.

my version is 6.2.1,my purpose is to let my local computer can connect to remote computer again when it can’t open("/net/hostname"),in other way to find “/net/hostname” again

Why don’t you wrap the open fonction with your own fonction. If the open fails you do the ls and then try the open again. That way you don’t do ls if you don’t have to.

You could also do the ls yourself in the program by doing an opendir, which I guess would trigger qnet to do run through the discovery process. Maybe there is a cleaner way to get QNET to run the discovery process but I don’t know about it.