in reply to Tk Form GUI / external process error

What? No replies yet? You're lucky I'm still alive. :-)

What you need to do is spawn your external process, so that you get a pid returned for the process spawned. Then you can "kill -9 ( me ducks :-) ) the pid from the parent process. Just choose a way to spawn the external process, and stuff the returned pid into a hash. Then you can retreive and kill that pid. You may also need to use Proc::KillFam, since often, the spawning first gets a shell, then the shell runs the program. But if you killfam the shell's pid, you get it's descendants too.


I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
  • Comment on Re: Tk Form GUI / external process error

Replies are listed 'Best First'.
Re^2: Tk Form GUI / external process error
by honyok (Sexton) on Mar 26, 2009 at 18:17 UTC
    After trial/error, I'm very very close. I'm capturing the subprocess ID with the following:
    $sub_pid= open $pipe, "-|", "${tab}_${date}.sh 2>&1" or die "Can't exe +cute $tab : $!\n";
    then kill the process with:
    my $button = $popup->Button( -text => 'Kill', -command => [sub{`kill $sub_pid 2>&1` && warn "Can't kill subpro +cess: $sub_pid\n"}],-background=>'slate grey'); $button->pack;
    Unfortunately $sub_pid returns 10523 rather than 10524. ps shows:
    PID TTY TIME CMD
    10514 pts/6 00:00:00 tools_generic.p
    10523 pts/6 00:00:00 program1_125919
    10524 pts/6 00:00:00 program1
    10525 pts/6 00:00:00 ps
    26437 pts/6 00:00:00 bas

    I suppose this is a sub launching a sub? Therefore I must use KillFam?

    So close!
    honyok

      Here is an example. Some commands need IPC::Open3, and you do "my $pid = open3(.....)
      #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(-background => 'gray50'); my $text = $mw->Scrolled('Text')->pack(); my $pid; my $startb = $mw->Button( -text => 'Start', -command=> \&work, )->pack(); my $count = 0; my $label = $mw->Label(-textvariable=>\$count)->pack(); my $testtimer = $mw->repeat(500, sub { $count++} ); my $stopb = $mw->Button( -text => 'Exit', -command=>sub{ kill 9,$pid; exit; }, )->pack(); MainLoop; ##################################### sub work{ $startb->configure(-state=>'disabled'); use Fcntl; + my $flags; + #long 10 second delay between outputs $pid = open (my $fh, "top -b -d 10 |" ) or warn "$!\n"; fcntl($fh, F_SETFL, O_NONBLOCK) || die "$!\n"; # Set the non-block f +lags my $repeater; $repeater = $mw->repeat(10, sub { if(my $bytes = sysread( $fh, my $buf, 1024)){; $text->insert('end',$buf); $text->see('end'); } } ); }

      P.S. Hurry with your questions, I won't be here for long...:-)


      I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
        Thanks! Unfortunately I don't have administrative rights on the system, so I have to request new package installs from IT. I'll let you know if I get this resolved soon.
        Is there some install command which loads bundles of commonly used packages??
Re^2: Tk Form GUI / external process error
by honyok (Sexton) on Mar 26, 2009 at 16:29 UTC
    Zentara, the Immortal!!
    By "spawn" do you mean something like "fork"? Is there any way to capture the pid using the  open $pipe, "-|", "${tab}_${date}.sh 2>&1" method?

    Thank you. -honyok