Hallo, [Alles mögliche gestrichen] Wie wäre es damit? Die wichtige Änderung ist hervorgehoben. #!/usr/bin/perl -w use warnings; use strict; use Socket; use IO::Handle; use POSIX ":sys_wait_h"; use POSIX 'setsid'; # thousands of lines just for autoflush :-( # We say AF_UNIX because although *_LOCAL is the # POSIX 1003.1g form of the constant, many machines # still don't have it. my ($pid,$line); my ($kid,$parent); new_socket(); my $kid_pid = fork_kid(); if ( $parent ) { #parent my $alive; for ( my $i=0 ; ( $i<20 ) && ( $kid == 0) ; $i++) { $alive=kid_alive($kid_pid); if ($alive) { print CHILD "DO\n"; } else { new_socket(); $kid_pid=fork_kid(); } sleep 1; print "$i\n"; #Mitzählen } # maybe we forked because kid died, # so "kid" can occur in parent process. # Get out here, go kid. if ( $parent ) { print "died as parent\n"; print CHILD "DIE\n"; waitpid($kid_pid,0); } if ( $kid ) { print "died as kid\n"; } } if ($kid) { #child print "kid runs\n"; srand; while (1) { $line = <PARENT>; chomp $line; if ( $line eq "HELLO" ) { print PARENT "SMACK\n"; } if ( $line eq "DO" ) { if ( int(rand(100)) < 30 ) { die "e\n"; } } if ( $line eq "DIE" ) { close PARENT; exit; } } } sleep 4; sub fork_kid { $pid = fork; if ($pid != 0) { #parent close PARENT; $parent=-1; $kid=0; return $pid; } else { #kid die "cannot fork: $!" unless defined $pid; close CHILD; setsid or die "Can't start a new session: $!"; $parent=0; $kid=-1; return 0; } } sub kid_alive { my $pid=shift; if (! defined $pid ) { return 0; } # Undefined pid: Never forked before my $kid = waitpid( $pid , WNOHANG); #Aenderung!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! BEGIN print $kid."\n"; #Kann gestrichen werden #Bei mir war der Wert von $kid immer 0, wenn das Kind noch lebte if ( $kid != 0 ) { return 0; } #Aenderung!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ENDE # No such process # Found a(!) process. Is it the right one? print CHILD "HELLO\n"; chomp(my $line = <CHILD>); if ( $line eq "SMACK" ) { return 1; } # Kid's alive and replies return 0; # Uh. Rang the wrong door, or kid's dead. } sub new_socket { socketpair(CHILD, PARENT, AF_UNIX, SOCK_STREAM, PF_UNSPEC) or die "socketpair: $!"; CHILD->autoflush(1); PARENT->autoflush(1); } Ich kann das allerdings nicht begründen. Das beruht nur auf der Tatsache, dass ich das so beobachtete und es funzt. Ferdinand