mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-07-13 19:31:49 +02:00
check status of child exiting and use that to send sigint to all the child processes from the parent
This commit is contained in:
@ -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";
|
||||||
|
Reference in New Issue
Block a user