[Vienna-pm] unterschiedliches SIGNAL-Trapping in den Childs und der Mama

gooly at gmx.at gooly at gmx.at
Thu Apr 5 01:42:40 PDT 2007


Also,

für jeden, der's probieren will - so (siehe unten) geht's nicht!
Ich habe die version genommen von:
	http://www.cpanforum.com/posts/4756
und für mich umgearbeitet - mein Problem bleibt das Gleich das sleep des 
Child wird nicht unterbrochen und das Kind stirbt still, ohne chance 
auf irgendwas. Gekillt habe ich auf konsole mit Kill -USR1 pid
das produziert dort wo das prg lief:
./testSIG.pl
7826 => Mum  starting: threads=SCALAR(0x82414a8)
7826 => MyPack starting:  >1<
7826 => MyPack going to sleep ..
7826 => Mum  caught $SIG{ USR1 } killing:threads=SCALAR(0x82414a8) at 7
7826 => Mum  caught $SIG{ USR1 } killing myself NOW!  9

Kein Seufzer, nicht ein Ton vom Kind - friede seiner Asche.
Jetzt versuch ich den original Text aus cpan..
Bis gleich,
Calli

#!/usr/bin/perl

use strict;
use warnings;
use threads;           # pull in threading routines
use threads::shared;   # and variable sharing routines

our ($thr,$tme);
# killing sub:
   for my $k ( keys %SIG ) {
      $SIG{$k} = sub {
            print "$$ => Mum    caught \$SIG{ $k } killing:$thr at ",
(time-$tme),"\n";
            $thr->kill('USR1');
            sleep(2);
            print "$$ => Mum    caught \$SIG{ $k } killing myself 
NOW!  ",(time-$tme),"\n";
            $SIG{INT} = 'DEFAULT';
            kill('INT', $$);
      }
   }

# detach child:
      $thr = threads->new(\&MyPack::run, ID => 'MyPack' );
      $tme = time;
      $thr->detach();
      print "$$ => Mum    starting: $thr\n";
# stay allive
      while ( 1 ) { 
         sleep 1; 
      }



#####
package MyPack; #: detached process to receive the Client's Input
use threads;
use threads::shared;
our $thrID;

sub new { #: create FoxiRu
    my $pkg = shift; #: Package
    my $self = { @_ };
    return bless($self, $pkg); ##:  arr of blessed (self, pkg)
}

sub run { #: runs until the socket of this FoxiRu dies; reads from the 
socket and pushs it into @chat

   my $self = MyPack->new(@_); #: Me
   $thrID   = $self->{ID}; #:
   $|++;
   
      my $term = 0;
      my $tme = time;
      for my $k ( keys %SIG ) {
         $SIG{$k} = sub { print "$$: Child Caught \$SIG{ $k }  time:",
(time-$tme),"\n"; $term = 1; };
      }
      #my %cntSymbol = ();
      print "$$ => $thrID starting:  >".($^S)."<  \n";#$^S
      my $n = 0;
      while ( ! $term ) {
         print "$$ => $thrID going to sleep ..\n"; # unless (time%2);
         # sleep länger => weniger Lines, kürzer bei mehr Lines
         sleep 30;
         print "$$ => $thrID ",$n++,"\tChild's SIGNAL caught :$term< 
time:",(time-$tme),"\n";
         #system ('ps  -C  testSIG.pl');
      } # while exists PIP
      print "$$ => $thrID Loop Left Time:",(time-$tme),"\n";
      
}



More information about the Vienna-pm mailing list