gaojie@zs-gaojie:~$ cat signal.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/types.h>
//信号处理方法
void sighandler(int signo){
printf("sighandler:%d\n", signo);
}
int main(){
//typedef void (*sighandler_t)(int);
//sighandler_t signal(int signum, sighandler_t handler);
//注册处理ctrl+c(2)的信号.
printf("signal: SIGINT\n");
signal(SIGINT, sighandler);
//注册处理kill(15)的信号
printf("signal: SIGTERM\n");
signal(SIGTERM, sighandler);
fflush(stdout);
p:
pause();
printf("signal down...");
//继续pause, 处理完后.
goto p;
return EXIT_SUCCESS;
}
转载于:https://my.oschina.net/u/139611/blog/182796