in reply to Creating a Pipe

Several issues.

  1. you are doing 2 forks.
  2. you confounded parent and child code. The child writes to, the parent reads from the pipe.
    if ($pid = fork) { # parent ... } elsif ($pid == 0) { child ... exit; }
  3. don't forget to exit the child in the elsif branch to stop it executing any following code of the parent.
  4. you need a signal handler in the parent for it to get notified about the child having exited.
    Otherwise the parent will try to get a line from its pipe handle when there isn't any.

Last, you need loops in the parent and the child functions for the repeating to happen.

pipe(PIPE_READ,PIPE_WRITE); autoflush PIPE_WRITE 1; #my $pid = fork(); if ($pid = fork) { # parent $SIG{CHLD} = \&chld_handler; &read_pipe; } elsif (defined $pid) { # child &write_pipe ($pid); exit; } else { die "cannot fork: $!"; } sub chld_handler { warn "parent got signal @_\n"; waitpid($pid,0); exit; } sub write_pipe { print "child pid $$ \n"; while(1) { sleep 1; print "Enter message: "; my $usr_msg = <STDIN>; chomp $usr_msg; last unless $usr_msg; print "child pid = $$ message = $usr_msg\n"; print PIPE_WRITE "$usr_msg\n"; } } sub read_pipe { print "parent here. child pid = $pid\n"; while ( my $msg_read = <PIPE_READ>) { print "received from pipe $msg_read"; } }

Try to fix your program first, then read the spoiler ;-)

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'