Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!midway!msuinfo!frith.egr.msu.edu!winnard From: winnard@frith.msu.edu Newsgroups: comp.unix.questions Subject: Problem with sleep and signal/alarm. Message-ID: <1991May6.153937.28635@msuinfo.cl.msu.edu> Date: 6 May 91 15:39:37 GMT Sender: news@msuinfo.cl.msu.edu Organization: Michigan State University, College of Engineering Lines: 34 Originator: winnard@frith.egr.msu.edu I'm having trouble getting the sleep function to work under C when I use signal/alarm function. When the signal/alarm call is taken out of the following code, the program will print "Sleep 10..." then it will wait 10 seconds before printing how long it did not sleep every time through the loop. But with the signal/alarm function in place the sleep will return immediately and still indicate that it slept 10 seconds every time through the loop. #include #include #include main() { int x; signal( SIGALRM, SIG_IGN ); alarm( 1 ); while( 1 ) { printf("Sleep 10..."); x = sleep( (unsigned)10 ); if( x == -1 ) perror(""); else printf("unslept %d\n", x ); } } If you don't know why this is happening maybe you know a way to timeout a read function. Either solution would be of great help. Thanks. Jamie Winnard winnard@frith.egr.msu.edu