#!/usr/local/bin/perl -w pipe PIPEIN1,PIPEOUT1;#pipe1 pipe PIPEIN2,PIPEOUT2;#pipe2 $command1=<STDIN>; # read command 1 from user chomp($command1); # remove new line character $command2=<STDIN>; # read command 2 from user chomp($command2); # remove new line character $command3=<STDIN>; # read command 3 from user chomp($command3); # remove new line character if (fork ==0)#child 1 { close PIPEIN1; # close pipe in 1 close PIPEIN2; # close pipe in 2 close PIPEOUT2; # close pipe out 2 close STDOUT; # close standard out open STDOUT, ">&PIPEOUT1"; #open standard out and pipe1 exec $command1; } if (fork==0)#child 2 { close PIPEIN2; #close pipe in 2 close PIPEOUT1; # close pipe out 1 close STDIN; # close standard in open STDIN, "<&PIPEIN1";# open standard in and pipe1 close STDOUT; # close standard out open STDOUT, ">&PIPEOUT2";# open standard out and pipe 2 exec $command2; } if (fork==0)#child 3 { close PIPEIN1; # close pipe in 1 close PIPEOUT1; # close pipe out 1 close PIPEOUT2; # close pipe out 2 close STDIN; # close standard in open STDIN, "<&PIPEIN2"; # open standard in and pipe in 2 exec $command3; } close PIPEIN1; # close pipe in 1 close PIPEOUT1; # close pipe out 1 close PIPEIN2; # close pipe in 2 close PIPEOUT2; # close pipe out 2 wait; # wait for child 1 to terminate wait; # wait for child 2 to terminate wait; # wait for child 3 to terminate
Edit - Masem added code tags
Edit - ar0n More descriptive title
In reply to Forking Multiple Children by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |