check status of child exiting and use that to send sigint to all the child processes from the parent
All checks were successful
Build on RHEL9 / build (push) Successful in 3m36s
Build on RHEL8 / build (push) Successful in 5m2s

This commit is contained in:
2025-07-10 12:36:45 +02:00
parent af51776eef
commit 1bf3d5e67a

View File

@ -212,17 +212,15 @@ int main(int argc, char *argv[]) {
// each child process gets a copy of the semaphore // each child process gets a copy of the semaphore
sem_wait(&semaphore); sem_wait(&semaphore);
sem_destroy(&semaphore); sem_destroy(&semaphore);
LOG(sls::logINFOBLUE)
<< "Exiting Child Process [ Tid: " << gettid() << ']';
exit(EXIT_SUCCESS);
} catch (...) { } catch (...) {
sem_destroy(&semaphore); sem_destroy(&semaphore);
LOG(sls::logINFOBLUE) LOG(sls::logINFOBLUE)
<< "Exiting Child Process [ Tid: " << gettid() << " ]"; << "Exiting Child Process [ Tid: " << gettid() << " ]";
throw; exit(EXIT_FAILURE);
} }
LOG(sls::logINFOBLUE)
<< "Exiting Child Process [ Tid: " << gettid() << ']';
return EXIT_SUCCESS;
} }
} }
@ -236,7 +234,8 @@ int main(int argc, char *argv[]) {
/** - Parent process waits for all child processes to exit */ /** - Parent process waits for all child processes to exit */
for (;;) { for (;;) {
pid_t childPid = waitpid(-1, nullptr, 0); int status;
pid_t childPid = waitpid(-1, &status, 0);
// no child closed // no child closed
if (childPid == -1) { if (childPid == -1) {
@ -250,6 +249,12 @@ int main(int argc, char *argv[]) {
break; break;
} }
} }
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
std::cerr << "Child " << childPid << " failed\n";
kill(0, SIGINT); // signal other children to exit
}
} }
std::cout << "Goodbye!\n"; std::cout << "Goodbye!\n";