Thank you very much. The hint with the shell helps me a lot.

Here a solution which is working for Linux and Windows:

#!perl -slw use strict; use threads; use threads::shared; use Thread::Queue; ## A shared var to communicate progess between work thread and TK my $Q = new Thread::Queue; my $pid:shared; sub work{ if( $^O eq "linux" ) { $pid = open PROC, "-|", "perl", "-le", '$|=1; print and select(undef,undef,undef,0.1) for 1 .. 1000' or die $!; } elsif( $^O eq "MSWin32" ) { $pid = open PROC, 'perl -le"$|=1; print and select(undef,undef,undef,0.1) for 1 .. 1 +000" |' or die $!; } else { die "Not implemented for $^O"; } if( $pid ) { while( <PROC> ) { $Q->enqueue( $_ ); } close PROC; } } threads->new( \&work )->detach; ## For lowest memory consumption require (not use) ## Tk::* after you've started the work thread. use Tk; use Tk::ProgressBar; my $mw = MainWindow->new; my $pb = $mw->ProgressBar()->pack(); my $repeat; $repeat = $mw->repeat( 100 => sub { while( $Q->pending ) { my $progress = $Q->dequeue; return unless $progress; $repeat->cancel if $progress == 100; $pb->value( $progress ) } } ); $mw->Button('-text' => 'Cancel', '-command' => sub{ kill 9, $pid })->pack(); $mw->MainLoop;

In perlipc I read that if you give an open to minus more than 3 arguments, than the shell is not called.

This solution is ok for me. But of course I'd prefer how to find out the pid of the process I want to kill. Independent whether it is called by a shell or not.

And the other interesting question is why linux is using a shell and windows not?

Greetings,

Dirk


In reply to Re^2: Tk and IPC - killing of process not working in Linux by Dirk80
in thread Tk and IPC - killing of process not working in Linux by Dirk80

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.