From 1bf3d5e67a29fba37f600e5b921f23017ffa5794 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 10 Jul 2025 12:36:45 +0200 Subject: [PATCH] check status of child exiting and use that to send sigint to all the child processes from the parent --- slsReceiverSoftware/src/MultiReceiverApp.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/src/MultiReceiverApp.cpp b/slsReceiverSoftware/src/MultiReceiverApp.cpp index 75b8e2a9a..3e00942a8 100644 --- a/slsReceiverSoftware/src/MultiReceiverApp.cpp +++ b/slsReceiverSoftware/src/MultiReceiverApp.cpp @@ -212,17 +212,15 @@ int main(int argc, char *argv[]) { // each child process gets a copy of the semaphore sem_wait(&semaphore); sem_destroy(&semaphore); - + LOG(sls::logINFOBLUE) + << "Exiting Child Process [ Tid: " << gettid() << ']'; + exit(EXIT_SUCCESS); } catch (...) { sem_destroy(&semaphore); LOG(sls::logINFOBLUE) << "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 */ for (;;) { - pid_t childPid = waitpid(-1, nullptr, 0); + int status; + pid_t childPid = waitpid(-1, &status, 0); // no child closed if (childPid == -1) { @@ -250,6 +249,12 @@ int main(int argc, char *argv[]) { 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";