| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4699 人关注过本帖
标题:一个简单小例子说明signal的基本用法。
只看楼主 加入收藏
madfrogme
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:21
帖 子:1160
专家分:1106
注 册:2009-6-24
结帖率:98.63%
收藏
 问题点数:0 回复次数:0 
一个简单小例子说明signal的基本用法。
一个简单小例子说明signal的基本用法。

捕捉Ctrl+C( INT)

程序代码:
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

/* first, here is the signal handler */
void catch_int(int sig_num) {
    /* re-set the signal handler again to 
     * catch_int, for next time 
     */
    signal(SIGINT, catch_int);
    printf("Dont't do that\n");
    fflush(stdout);
}

int main(int argc, char *argv[]) {
    /* set the INT (Ctrl-C) signal handler to 
     * 'catch_int
     */
    signal(SIGINT, catch_int);

    /* now, lets get into an infinite loop of doing
     * nothing
     */
    for( ; ; )
        pause();
}
搜索更多相关主题的帖子: include next 
2012-08-10 15:41
快速回复:一个简单小例子说明signal的基本用法。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011103 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved