linux内核alarm,Linux--C库函数alarm中文翻译

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.

如果seconds是0,没有新的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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值