I have tried to replace sleep() by SIGALRM.
#include <signal.h>
#include <unistd.h>
void sig_alrm( int signo )
{
return; /* return to wake up pause */
}
unsigned int sleep1( unsigned int nsecs )
{
if( signal( SIGALRM, sig_alrm ) == SIG_ERR )
return (nsecs);
alarm( nsecs ); /* starts timer */
pause(); /* next caught signal wakes */
return( alarm( 0 ) ); /* turn off timer, return unslept*/
}
Is this correct implementation? Is there another implementation?