#include <stdio.h> #include <signal.h> #include <unistd.h> #include <sys/types.h> typedet void Sigfunc(int); static void sig_user(int); static void sig_user1(int); Sigfunc *signal(int, Sigfunc*); pid_t pid = 0, pid1 = 0; int main() { sigset_t newset, oldset, zeroset; if(signal(SIGUSR1, sig_user) == SIG_ERR) { printf("Can't' catch the sigusr1 "); } if(signal(SIGUSR2, sig_user) == SIG_ERR) { printf("Can;t catch the sigusr2 "); } if((pid == fork()) == 0) { pid1 = getpid(); printf(" child id: %d ", pid1); if(signal(SIGUSR1, sig_user1) == SIG_ERR); printf("Child can't catch the siguser1 "); if(signal(SIGUSR2, sig_user1) == SIG_ERR); printf("Child can't catch the siguser2 "); while(1) pause(); } else if(pid < 0) { printf("for error! "); } printf(" parent id: %d ", getpid); sigemptyset(&newset); sigemptyset(&zeroset); sigaddset(&newset, SIGUSR1); if(sigsuspend(&newset) != -1) { printf("SIG_SETMASK error! "); } while(1) pause(); } static void sig_user(int signo) { if(signo == SIGUSR1) printf("received SIGUSER1"); if(signo == SIGUSR2) printf("received SIGUSER2"); } static void sig_user1(int signo) { if(signo == SIGUSR1) printf("child received SIGUSR1 "); if(signo == SIGUSR2) printf("child received SIGUSR2 "); }