sleep1.c
来自「UNIX编程高级环境(第二版)的信号部分的程序源码」· C语言 代码 · 共 19 行
C
19 行
#include <signal.h>
#include <unistd.h>
static void
sig_alrm(int signo)
{
return; /* nothing to do, just return to wake up the pause */
}
unsigned int
sleep1(unsigned int nsecs)
{
if (signal(SIGALRM, sig_alrm) == SIG_ERR)
return(nsecs);
alarm(nsecs); /* start the timer */
pause(); /* next caught signal wakes us up */
return( alarm(0) ); /* turn off timer, return unslept time */
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?