aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2024-09-27 10:04:39 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2024-09-27 10:04:39 -0400
commit8012b6f930210701dd62f2ffb21247e58037d80f (patch)
tree14f9dbd3697d6de527cf327cb7fd9a29f5e37399
parentd657705546d8a4758ec1c65ce13ae7d2f954bc95 (diff)
downloadstasis-8012b6f930210701dd62f2ffb21247e58037d80f.tar.gz
Show "Task is running" every X seconds, instead of X iterations
-rw-r--r--src/multiprocessing.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/multiprocessing.c b/src/multiprocessing.c
index bd4678a..6a97b3b 100644
--- a/src/multiprocessing.c
+++ b/src/multiprocessing.c
@@ -234,8 +234,8 @@ int mp_pool_kill(struct MultiProcessingPool *pool, int signum) {
int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) {
int status = 0;
- int watcher = 0;
int failures = 0;
+ time_t watcher = time(NULL);
size_t tasks_complete = 0;
size_t lower_i = 0;
size_t upper_i = jobs;
@@ -253,7 +253,7 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) {
fprintf(stderr, "%s: mp_task_fork failed\n", slot->ident);
kill(0, SIGTERM);
}
- }
+ }
// Has the child been processed already?
if (slot->pid == MP_POOL_PID_UNUSED) {
@@ -343,11 +343,12 @@ int mp_pool_join(struct MultiProcessingPool *pool, size_t jobs, size_t flags) {
fprintf(stderr, "waitpid failed: %s\n", strerror(errno));
return -1;
} else {
- if (watcher > 9) {
+ time_t watcher_diff = time(NULL) - watcher;
+ if (watcher_diff == 0) {
printf("[%s:%s] Task is running (pid: %d)\n", pool->ident, slot->ident, slot->parent_pid);
- watcher = 0;
- } else {
- watcher++;
+ }
+ if (watcher > 9) {
+ watcher = time(NULL);
}
}
}