From fbaed163427ca260d1e81ebfc8f513a90d73064d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 28 Jun 2021 16:26:49 +0200 Subject: wpdf: Exit when all children have exited --- wpdf | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'wpdf') 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"; -- cgit v1.2.3