I have the following situation: Thread 1: Forks a child and the child, say A in turn forks again and executes a process. B
Thread 2: Listens for commands over a Unix Domain Socket and kills the process, B that has been forked by child, A in Thread 1 Respond to caller that it has killed the child
I want to ignore SIGPIPE for Thread 2 as I do not want the program to crash when client has closed the socket. So i tried doing this using
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set, NULL);
Doing this helps block SIGPIPE but it also blocks the ability of the thread 1 to send SIGKILL to the child.
I also tried using the below in main function before creating threads
signal(SIG_IGN, SIGPIPE);
and send with MSG_NOSIGNAL flag in socket.
This doesnt help my scenario with SIGKILL as well. Any idea how to ignore safely the SIGPIPE in a multi-threaded condition like above with forks and execs and SIGKILLs sent?