发送SIGUSR1信号,接收到处理完信号之后程序继续运行
- #include <unistd.h>
- #include <sys/types.h>
- #include <signal.h>
- #include <stdio.h>
- void sig_usr(int signo){
- printf("get signo SIGUSR1\n");
- }
- int main(){
- int i;
- int j;
- signal(SIGUSR1, sig_usr);
- for(i = 1; i < 10; i++){
- if(i%3 == 0){
- printf("send sig SIGUSR1\n");
- kill(getpid(), SIGUSR1);
- }
- else{
- printf("the normal num is %d\n",i);
- }
- }
- printf("\nthe final i is %d\n", i);
-
- return 0;
- }
结果如下:
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
阅读(1054) | 评论(0) | 转发(0) |