Hello Bob,
Thank you for getting back to me so quickly,
Unfortunately I was not using the <unistd.h> header in my C
application, I tried adding this header and it didn't make a difference...I
assume then that without the unistd.h my application was using the shell
version of sleep, is there a difference with the shell sleep and C's
sleep(1); ?
Basically this is what my loop looks like in my application: (I'm
only including sections of the code that are relevant to your
understandings.)
struct sigaction isas;
sig = SIGUSR1;
/*this is declared globally */
void sig_handler (int sig)
{
req_completed = TRUE;
}
bla bla bla...
sigemptyset (&isas.sa_mask);
isas.sa_flags = 0;
isas.sa_handler = sig_handler;
sigaction (sig,&isas, NULL);
bla bla bla...
req_completed = FALSE;
while (req_completed == FALSE)
{
sleep(1);
}
...Again if I leave the sleep in there, it will never exit, if I
take it out, the application will exit this loop once the OS triggers a
signal.
I tried the targeted test of just sleep and I also got 130 on my machine,
the version of sleep is sh-utils 2.0
I really appreciate your help in this matter (thank God for you guys out
there !!!)
Regards,
Sergio Gazzola
-----Original Message-----
From: Bob Proulx [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 12, 2000 11:55 AM
To: Sergio Gazzola
Subject: Re: I believe there is a BUG with the sleep command
Hello
> I'm not certain if this is a bug, however I'm using an application
> that uses signals from the operating system. When my program waits for a
> signal in a while loop and performs a "sleep(1)" in the loop, it never
> receives the signal (remains stuck in my loop) . However if I remove the
> sleep(1), it works just fine, gets a signal and jumps out of the loop.
Just a couple of comments. I assume your loop is something like the
following:
while sleep 1; do
:
done
I think the sleep should exit with a non-zero exit status. The while
should see that $? is non-zero and exit the loop. But here is a case
where it probably won't exit the loop.
while sleep 1; do
sleep 10 # representing middle code
done
Here the odds are that the middle code will get the signal since that
takes longer and then the loop will continue.
while sleep 1; do
sleep 10 # representing middle code
if [ $? -ne 0 ]; then
exit 1
fi
done
Here is a couple of things to try. Debugging sleep in conjunction
with a while loop confuses things. Let's try a targeted test of just
sleep.
sleep 10
# Interrupt the command with your interupt character, usually Control-C.
echo $?
That should be non-zero. It is actually 130 on my machine using sleep
from sh-utils 2.0. If it is not then there is a problem. Do the same
test again using whatever signal you were sending it.
What version of sleep were you using? Use sleep --version to find
that out.
Bob Proulx
Regards,
Sergio Gazzola
RAD/WAN -Software Development
Eicon Technology