You should consider calling sigwait after to see if this pid is a child process.
So maybe put
int sig;
and
int result = sigwait (& sigset, & sig);
inside an if statement, which checks if pid == 0, which indicates that it is a child. Otherwise, you will expect from the parent process.
If pid is greater than 0, this is the parent identifier of the process, and if it is less than zero, its error.
Then for each process in your pids array, you can call kill (pid_array [i], SIGUSR1) to unlock it.
chups source share