捕获SIGUSR1信号
void catch_Signal(int Sign) { switch (Sign) { case SIGINT: printf("SIGINT Signal "); exit(0); case SIGUSR1: printf("SIGUSR1 Signal "); } } int main(int arg, char *args[]) { signal(SIGINT, catch_Signal); signal(SIGUSR1, catch_Signal); printf("pid = %d ", getpid()); while(1) { sleep(1); } return 0; }
发送SIGUSR1信号
int main(int arg, char *args[]) { if (arg > 1) { kill(atoi(args[1]), SIGUSR1); printf("sent to %d ", atoi(args[1])); } return 0; }