"Use POSIX": Sys_wait_h ";" Remove, and it is wrong to print the variables in the subprocess in the main process, the main process does not know the status of the child process, unless you pass the value of the variable to the main process with a pipe, ################################################## #!/
Usr/bin/perl #use POSIX ": Sys_wait_h";
my $a = 10;
for ($i =1; $i <=3; $i + +) {my $pid =fork ();
if (!defined ($pid)) {print "Error in fork: $!";
Exit 1;
if ($pid = = 0) {if ($i ==1) {sleep (9);
$b 1= $a +1;
Print "$b 1\t";
Exit 0;}
elsif ($i ==2) {sleep (5);
$b 2= $a +10;
Print "$b 2\t";
Exit 0;}
else{sleep (3);
$b 3= $a +100;
Print "$b 3\t"; Exit 0;
}}} print "~~~~~~~~~~split~~~~~~~~~~~\n";
while (($collect = Waitpid ( -1, Wnohang)) > 0) {1;} ##################### output ########## bsd2# perl test.pl ~~~~~~~~~~split~~~~~~~~~~~ bsd2#