aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-06-28 16:26:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-06-28 16:26:49 +0200
commitfbaed163427ca260d1e81ebfc8f513a90d73064d (patch)
treee420dac271fdd07a4d1b5b7774abd0e3b42bc7aa
parent8b6d11f191a0336a47aea1f13c9af48ac17864e3 (diff)
downloadxutil-fbaed163427ca260d1e81ebfc8f513a90d73064d.tar.gz
wpdf: Exit when all children have exited
-rwxr-xr-xwpdf13
1 files changed, 11 insertions, 2 deletions
diff --git a/wpdf b/wpdf
index 99fa525..5700bc4 100755
--- a/wpdf
+++ b/wpdf
@@ -5,7 +5,11 @@
use strict;
use warnings;
-my %deptarget; # dependency => target
+my $alive; # number of children alive
+my %deptarget; # dependency => target
+my $parent = $$; # pid of parent
+
+$SIG{HUP} = sub { kill 'INT', $parent if not --$alive };
# collect dependencies for given pdf files
for my $target (@ARGV) {
@@ -27,7 +31,12 @@ for my $target (@ARGV) {
}
}
close $f;
- exec('xpdf', '-remote', "wpdf-$target", $target) if fork == 0;
+ if (fork == 0) {
+ system 'xpdf', '-remote', "wpdf-$target", $target;
+ kill 'HUP', $parent;
+ exit;
+ }
+ $alive++;
next;
} else {
warn "skipping $_: not a pdf\n";