打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
uc信号处理函数 alarm 设置信号传送闹钟

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$



本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Linux 定时器alarm()(转)
Linux进程之alarm()信号传送闹钟函数
10.19 sleep,nanosleep以及clock
深入理解计算机系统:进程
异步通信信号
多线程中定时器的使用
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服