Hey guys, i have an assignment for my perl class which is the following:
Create a pipe
Fork a sub-process
Parent gets a message from the user, sends it to the child
Child gets the message, prints it to the screen
Repeat until user doesn't enter a message
This is what I have so far and cant seem to get it to work properly, please help me with this simple code!
pipe(PIPE_READ,PIPE_WRITE); autoflush PIPE_WRITE 1; my $pid = fork(); if ($pid = fork) { &write_pipe ($pid); waitpid($pid,0); } elsif (defined $pid) { &read_pipe; } else { die "cannot fork: $!"; } sub write_pipe { print "pid $$ \n"; print "Enter message: "; sleep 1; my $usr_msg = <>; print "Parent pid = $$ message = $usr_msg"; print PIPE_WRITE "$usr_msg\n"; } sub read_pipe { print "child pid = $pid"; my $msg_read = <PIPE_READ>; print "received from pipe $msg_read"; }
In reply to Creating a Pipe by grjoe21
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |