c实现signal函数实例

来源:互联网 发布:apache网络服务器 编辑:程序博客网 时间:2024/05/18 14:24
#include <signal.h>#include <unistd.h>void sig_hander(int signum){    printf("catch the signal %d\n",signum);    return ;}int main(int argc,char **argv){    pid_t pid;    pid = getpid();    printf("pid[%d]\n",getpid());    if(signal(SIGINT,sig_hander)==SIG_ERR)    {        printf("catch error!\n");        return -1;    }    while(1);    return 0;}

执行:

momo@momo:mydev/cc $ a.out
pid[8675]
^Ccatch the signal 2
^Ccatch the signal 2
^Ccatch the signal 2