NAME
alarm - set an alarm clock for delivery of a signal
SYNOPSIS
#include <unistd.h>
unsigned int alarm(unsigned int seconds);
DESCRIPTION
alarm() arranges for a SIGALRM signal to be delivered to the calling
process in seconds seconds.
If seconds is zero, no new alarm() is scheduled.
In any event any previously set alarm() is canceled.
函数说明:alarm()用来设置信号SIGALRM在参数sceonds指定的秒数后传递给当前调用的进程。如果参数sceonds为0,没有新的闹钟被设定,之前预设的闹钟被取消。RETURN VALUE
alarm() returns the number of seconds remaining until any previously
scheduled alarm was due to be delivered, or zero if there was no previ‐
ously scheduled alarm.
返回值:alarm()返回之前闹钟的剩余秒数。如果之前没设闹钟返回0
1
/* 执行程序5秒后打印出hello字符串*/ 2 #include <unistd.h>
3 #include <signal.h>
4 #include <stdio.h>
5 void handler(int signum){
6
7 printf("hello\n");
8 return ;
9 }
10 int main(void){
11 int i;
12 signal(SIGALRM,handler);
13 alarm(5);
14 for(i = 1;i < 7;i++){
15 printf("sleep %d...\n",i);
16 sleep(1);
17 }
18
19 return 0;
20 }
执行后。。。
tarena@ubuntu:~/uc/day09$ ./a.out
sleep 1...
sleep 2...
sleep 3...
sleep 4...
sleep 5...
hello
sleep 6...tarena@ubuntu:~/uc/day09$
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。