die "can't fork: $!" unless defined($kidpid = fork()); if ($kidpid) { # We are the parent. Handle incoming my $header; my $body; while(1) { while (defined sysread $handle,$header,9,0) { print $header,"\n"; if($header =~ m/([A-Z]{4})(\d{5})/) { my $messagetype = $1; if($2 != 00000) { $2 =~ m/0+(\d+)/; #remove sysread $handle,$body,$1,0; #receive amount specified in header } check_header_type $messagetype, $body, $handle; #do things with this message } } } kill("TERM" => $kidpid); # send SIGTERM to child } ############################################### # Child Process ############################################### else { # Child. handle all sends while ($line = ) { chomp $line; if(!($line =~ m/\A#/)) #check for '#' in file as comment sign {syswrite DEBUG, "Got Line\n"; my $bod = add_header($line); syswrite $handle, $bod; } } }