aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-09-17 09:35:07 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-09-18 23:08:02 -0400
commit0f95b43e2d3853995106c5c6aa55bf92f63fb331 (patch)
treeefbe3728afa72554e75312f48e007d21e952a01d
parent3c3468d0c4bba45ed8626894613cc44e5fcd51c0 (diff)
downloadstasis-0f95b43e2d3853995106c5c6aa55bf92f63fb331.tar.gz
Wait for signaled processes to hang up
* Only initiate a kill if we have more than one process. The current process is already failed out, no need to terminate it again.
-rw-r--r--src/multiprocessing.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/multiprocessing.c b/src/multiprocessing.c
index 0c993d7..fe15ab6 100644
--- a/src/multiprocessing.c
+++ b/src/multiprocessing.c
@@ -189,6 +189,10 @@ int mp_pool_kill(struct MultiProcessingPool *pool, int signum) {
status = kill(slot->pid, signum);
if (status && errno != ESRCH) {
fprintf(stderr, "Task '%s' (pid: %d) did not respond: %s\n", slot->ident, slot->pid, strerror(errno));
+ // Wait for process to handle the signal, then set the status accordingly
+ if (waitpid(slot->pid, &status, 0) >= 0) {
+ slot->signaled_by = WTERMSIG(status);
+ }
}
}
if (!access(slot->log_file, F_OK)) {
@@ -271,7 +275,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) {
}
if (status >> 8 != 0 || (status & 0xff) != 0) {
fprintf(stderr, "%s Task failed\n", progress);
- if (flags & MP_POOL_FAIL_FAST) {
+ if (flags & MP_POOL_FAIL_FAST && pool->num_used > 1) {
mp_pool_kill(pool, SIGTERM);
return -2;
}