免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6168 | 回复: 6
打印 上一主题 下一主题

alarm(0)会产生SIGALRM信号吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-17 15:07 |只看该作者 |倒序浏览
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static void sig_alrm(int);

int
main(void)
{
    unsigned int nsec;
    signal(SIGALRM,sig_alrm);
    nsec = alarm(0);
    sleep(2);
    printf("alarm: %u\n", nsec);

    exit(0);
}

static void
sig_alrm(int signo)
{
    printf("SIGALAM Generated!\n");
        return;
}
执行结果:

alarm: 0
没有输出"SIGALAM Generated!\n",是不是不产生SIGALRM信号?

论坛徽章:
0
2 [报告]
发表于 2007-04-17 15:36 |只看该作者

关注一下,帮你顶。

论坛徽章:
0
3 [报告]
发表于 2007-04-17 15:48 |只看该作者
man alarm
  "unsigned int alarm(unsigned int seconds);
   If seconds is zero, no new alarm() is scheduled."
可见alarm(0)相当于禁用 alarm,不会产生alarm的signal。

论坛徽章:
0
4 [报告]
发表于 2007-04-17 15:49 |只看该作者
自己搞清楚了。。
man 3 alarm

DESCRIPTION
     This interface is made obsolete by setitimer(2).

     The alarm() function sets a timer to deliver the signal SIGALRM to the
     calling process after the specified number of seconds.  If an alarm has
     already been set with alarm() but has not been delivered, another call to
     alarm() will supersede the prior call.  The request alarm(0) voids the
     current alarm and the signal SIGALRM will not be delivered.

论坛徽章:
0
5 [报告]
发表于 2007-04-17 15:51 |只看该作者
原帖由 samuel1004 于 2007-4-17 15:07 发表
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
static void sig_alrm(int);

int
main(void)
{
    unsigned int nsec;
    signal(SIGALRM,sig_alrm);
    nsec = a ...


以后遇到系统调用的问题,应该先请教man,再发到论坛上来。不能偷懒,不然别人不会给回复。

  1. alarm arranges for a SIGALRM signal to be delivered to the process in seconds seconds.

  2. If seconds is zero, no new alarm is scheduled.
复制代码

论坛徽章:
0
6 [报告]
发表于 2007-04-17 15:51 |只看该作者

回复 3楼 kingwha 的帖子

刚没看到3楼的 呵呵 谢谢了

论坛徽章:
0
7 [报告]
发表于 2007-04-17 15:53 |只看该作者
原帖由 zx_wing 于 2007-4-17 15:51 发表


以后遇到系统调用的问题,应该先请教man,再发到论坛上来。不能偷懒,不然别人不会给回复。
[code]
alarm arranges for a SIGALRM signal to be delivered to the process in seconds seconds.

If seco ...


刚开始学,还没习惯用man,以后多注意了。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP