On 20 Feb 2008, at 22:50, David Meisner wrote:
> ok, the dtrace script will not terminate by itself. Furthermore,  
> system will not return until the dtrace finishes, which it won't by  
> itself. So I'm forking so I can run commands while the script is  
> running and then kill it later. Does that make sense?


Yes :)

The problem is that when you use an IO redirection in the argument to  
exec Perl has to use /bin/sh to run the command you give it - and  
it's /bin/sh that handles the redirection. So you end up with

perl
  \- sh
      \- dtrace

But the PID you have is for sh. When you ask sh nicely to exit  
(SIGINT) it doesn't want to because it's running another process  
(dtrace). So you could either find the PID of the dtrace process and  
kill that or send SIGKILL to sh which causes it to kill the dtrace  
process.

This works for me using one of the resource kit examples:

#!/usr/bin/perl

use strict;
use warnings;

my $pid = fork;
die "Fork failed ($!)\n" unless defined $pid;
exec 'examples/pl_flow.d > flow.log' unless $pid;

for ( 1 .. 3 ) {
     print "Waiting...\n";
     sleep 1;
}

kill 9, $pid;
1 while 0 < waitpid -1, 0;

It uses SIGKILL and then waits for both the child processes to die  
(waitpid) before itself exiting.

-- 
Andy Armstrong, Hexten




_______________________________________________
dtrace-discuss mailing list
[email protected]

Reply via email to