in reply to Control C; into a running system / exec?
Neither backticks (qx) or system return control to the perl program until they exit. You will have to do your own fork() call so the parent perl
program can do something while the child is running. Here's a small example of a parent sending SIGINT (what control-c sends) to a child.
Hope this helps...
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11165441 use warnings; $SIG{__WARN__} = sub { die @_ }; if( my $pid = fork ) { # parent sleep 1; kill 'INT', $pid; sleep 1; kill 'INT', $pid; sleep 1; kill 'TERM', $pid; print "parent waiting for child to exit\n"; wait; print "parent exited\n"; } elsif( defined $pid ) { # child print "child started\n"; $SIG{INT} = sub { print "child got SIGINT\n" }; $SIG{TERM} = sub { print "child got SIGTERM\n"; exit }; sleep 1 while 1; } else { die "fork failed"; }
|
---|