sleep1.c

来自「AUPE的源代码」· 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 + -
显示快捷键?