/* program to demonstrate that only if siginterrupt() is called * for a signal are system calls interrupted by that signal on Linux. * Invoke with '-t' arg: siginterrupt is called and program is interrupted. * without it, the program hangs until it gets an unhandled signal(eg ^C), * even though the handler is invoked. */ #include #include #include #include #include void sigalrm(int sig) { write(1,"ALARM!\n",7); } int main(int argc, char **argv, char **envp) { char buf[512]; int r; signal(SIGALRM, sigalrm); if( (argc > 1) && (argv[1] != 0L) && (argv[1][0]=='-') && (argv[1][1]=='t')) siginterrupt(SIGALRM,1); alarm(2); r=read(0,buf,512); printf("%d %s\n",errno,strerror(errno)); }