'why child can't send signal to parent

parent:

volatile int signalval = 0;
void signal_handle_c(int sig_num)
{
    printf("child SIGUSR1 ok\n");
    signalval = 1;
};
int main(int argc,char**argv){   
    struct sigaction act, oldact;   
    act.sa_handler = signal_handle_c;
    act.sa_flags = SA_NOMASK;//SA_ONESHOT |  
    pid_t pid=fork();   
    if (pid < 0)   
        printf("error in fork!");   
    else if (pid == 0) {
        printf("exec child!%s\n",argv[1]);
        int res = execl(argv[1], "testc", NULL);
        printf("res=%d", res); 
    }  
    else {  
        sleep(3);
        sigaction(SIGUSR1, &act, &oldact);
        printf("now parent\n");  
       
    }
    waitpid(pid,NULL,0);
    return 0;  
}

child:

volatile int signal_pipe_end = 0;
void signal_handle_c(int sig_num)
{
    printf("child IGUSR1 ok\n");
    signal_pipe_end = 1;
};
int main(int argc, char *argv[])
{
    printf("now child run!");
    while (1)
    {

        printf("now child send siganl\n");
        kill(getpid(), SIGUSR1);
        sleep(1);
    }   
}

parent try to receive the SIGUSR1 signal from child.but none! run result: exec child!./testc now child run!now child now parent i hope can printf "child SIGUSR1 ok". why child "kill" send signal fail.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source