After a fork call, i have one father that must send sigusr1 or sigusr2 (based on the value of the 'cod' variable) to his child. The child have to install the proper handlers before receiving sigusr1 or sigusr2. For doing so, i pause the father waiting for the child to signal him telling that he's done with the handler installation. The father is signaled by sigusr1 and the handler for this signal is installed before the fork call. However, it seems the father can't return from pause making me think that he actually never call the sigusr1 handler.
[...] typedef enum{FALSE, TRUE} boolean; boolean sigusr1setted = FALSE; boolean sigusr2setted = FALSE; void sigusr1_handler0(int signo){ return; } void sigusr1_handler(int signo){ sigusr1setted = TRUE; } void sigusr2_handler(int signo){ sigusr2setted = TRUE; } int main(int argc, char *argv[]){ [...] if(signal(SIGUSR1, sigusr1_handler0) == SIG_ERR){ perror("signal 0 error"); exit(EXIT_FAILURE); } pid = fork(); if (pid == 0){ if(signal(SIGUSR1, sigusr1_handler) == SIG_ERR){ perror("signal 1 error"); exit(EXIT_FAILURE); } if(signal(SIGUSR2, sigusr2_handler) == SIG_ERR){ perror("signal 2 error"); exit(EXIT_FAILURE); } kill(SIGUSR1, getppid()); // wake up parent by signaling him with sigusr1 // Wait for the parent to send the signals... pause(); if(sigusr1setted){ if(execl("Prog1", "Prog1", (char*)0) < 0){ perror("exec P1 error"); exit(EXIT_FAILURE); } } if(sigusr2setted){ if(execl("Prog2", "Prog2", (char*)0) < 0){ perror("exec P2 error"); exit(EXIT_FAILURE); } } // Should'nt reach this point : something went wrong... exit(EXIT_FAILURE); }else if (pid > 0){ // The father must wake only after the child has done with the handlers installation pause(); // Never reaches this point ... if (cod == 1) kill(SIGUSR1, pid); else kill(SIGUSR2, pid); // Wait for the child to complete.. if(wait(NULL) == -1){ perror("wait 2 error"); exit(EXIT_FAILURE); } [...] }else{ perror("fork 2 error"); exit(EXIT_FAILURE); } [...] exit(EXIT_SUCCESS); }
pause.booleanobjects) must have avolatile sig_atomic_ttype otherwise the code is undefined.exec*()family of functions. If the system call returns, it failed.