If I have a long system command, such as apt-cache search <some query> , there is a way to forward the SIGINT sent via ^C on the command line to the parent Perl process, so that all the child processes are obtained.
There is no desired behavior in this example. The signal is sent to the child process.
#!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use autodie;
I tried to find ways to get the pid of the child element that was created by the system("apt-cache search hi &") , but could not find it, so I tried the fork ing and exec process and the signal capture handler. This does not work because apt-cache itself starts several processes through the clone system call. Rewinding some logic to go through part of the process tree and clear
#!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use autodie; my $cpid; $SIG{INT} = sub { kill 'KILL', $cpid; exit; };
I assume that, in fact, I want to determine if the child process that started using system due to a signal like SIGINT so that I can clear the Perl script after myself or by walking the child processes and reaping them in such a way that weird marginal process control cases are handled cleanly and portable.
source share