Perl多进程程序的编写

用fork函数实现多进程。
 
fork()函数的行为是将目前进程复制一份,用于建立子进程。
其返回值,在子线程中是0,在父线程中是子线程号。
通过判断其返回值来控制各进程的行为。
 
例程:
 
my @pids;
my $pid = fork();
 
if (!defined($pid))
{
   print ("Fork process failured!\n");
   exit();
}

if ($pid == 0)
{
     push @pids, $pid;
  print ("This is a child process.\n");
}
else
{
  foreach (@pids) {
       waitpid($_,0); # 等待子线程
  }     
   print ("This is the parent process. All child processes have finished.\n");
}  
原文地址:https://www.cnblogs.com/nicebear/p/2354567.html