Chinaunix首页 | 论坛 | 博客
  • 博客访问: 538599
  • 博文数量: 156
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1183
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-22 11:42
文章分类

全部博文(156)

文章存档

2015年(67)

2014年(89)

分类: LINUX

2015-04-17 14:31:04

ALARM(2)                   Linux Programmer’s Manual                  ALARM(

2)

 

NAME

       alarm - set an alarm clock for delivery of a signal

       //alarm-设置信号传送时钟

SYNOPSIS

       #include

       //包含头文件

 

       unsigned int alarm(unsigned int seconds);

       //无符号整型,需要传入一个无符号整型的参数

 

DESCRIPTION

       alarm()  arranges for a SIGALRM signal to be delivered to the

       process in seconds seconds.

       //alarm() 安排一个SIGALRM信号在seconds参数指定的秒数后传送给目前的进程

 

       If seconds is zero, no new alarm() is scheduled.

       如果seconds0,没有新的alarm()计划

       In any event any previously set alarm() is cancelled.

       在任何情况下任何预先设定的alarm()取消了。

 

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 previously scheduled alarm.

       //alarm()返回剩余的秒数,直到任何先前预定的是由于被传送,如果之前未设闹钟则返回0

 

 NOTES

       alarm() and setitimer() share the same timer;  calls  to  one

       will interfere with use of the other.

       //alarm()setitimer()共享同一个定时器,调用一个将妨碍另一个使用

 

       sleep()  may  be  implemented  using SIGALRM; mixing calls to

       alarm() and sleep() is a bad idea.

       //sleep()可能会使用SIGALRM实现;混合调用alarm()sleep()是不好的想法

 

       Scheduling delays can, as ever, cause the  execution  of  the

       process to be delayed by an arbitrary amount of time.

       //一如既往,调度延迟可以导致过程的执行被任意的时间延迟。

 

CONFORMING TO

       SVr4, POSIX.1-2001, 4.3BSD

 

SEE ALSO

       gettimeofday(2),  pause(2),  select(2),  setitimer(2), sigac-

       tion(2), signal(2), sleep(3)

 

Linux                             1993-07-21                          ALARM(2)

 

for example

#include  

#include  

#include  

#include 

//包含头文件 

 

void sig_alarm()      //返回值是空的子函数

    exit(0);    //返回0

 

int main(int argc, char *argv[])  //  argc是命令行总的参数个数,argv[]是argc个参数,其中第0个参数是程序的全名,以后的参数 命令行后面跟的用户输入的参数

   signal(SIGALRM, sig_alarm);   //让内核做好准备,一旦接收到SIGALRM信号,就执行  sig_alarm

alarm(10);                   //10s后传送

   sleep(15);                //睡眠15s

  printf("Hello World!\n");    //输出Hello World!

    return 0;                //返回0

程序在10s后结束,并输出Hello World!

阅读(2052) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~