Chinaunix首页 | 论坛 | 博客
  • 博客访问: 473782
  • 博文数量: 120
  • 博客积分: 1853
  • 博客等级: 上尉
  • 技术积分: 1177
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-22 22:40
文章分类

全部博文(120)

文章存档

2013年(16)

2012年(104)

分类: LINUX

2012-05-25 23:34:59

发送SIGUSR1信号,接收到处理完信号之后程序继续运行

点击(此处)折叠或打开

  1. #include <unistd.h>
  2. #include <sys/types.h>
  3. #include <signal.h>
  4. #include <stdio.h>

  5. void sig_usr(int signo){
  6.     printf("get signo SIGUSR1\n");
  7. }

  8. int main(){

  9.     int i;
  10.     int j;

  11.     signal(SIGUSR1, sig_usr);
  12.     for(i = 1; i < 10; i++){
  13.         if(i%3 == 0){
  14.             printf("send sig SIGUSR1\n");
  15.             kill(getpid(), SIGUSR1);
  16.         }
  17.         else{
  18.             printf("the normal num is %d\n",i);
  19.         }
  20.     }

  21.     printf("\nthe final i is %d\n", i);
  22.     
  23.     return 0;
  24. }
结果如下:
the normal num is 1
the normal num is 2
send sig SIGUSR1
get signo SIGUSR1
the normal num is 4
the normal num is 5
send sig SIGUSR1
get signo SIGUSR1
the normal num is 7
the normal num is 8
send sig SIGUSR1
get signo SIGUSR1

the final i is 10

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