Using fork to create child processes : fork « System Functions « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » System Functions » fork 




Using fork to create child processes
     


#!/usr/bin/perl

use warnings;
use strict;

$| = 1;
my $pid = 0;
if $pid = fork() ) {
   print"Parent executing.\n" );
   sleep);
   print"Parent finished.\n" );
}
elsif defined$pid ) ) {
   print"Child executing.\n" );
   sleep);
   print"Child finished.\n" );
   exit();
}
else {
   die"Could not fork" );
}

   
    
    
    
    
  














Related examples in the same category
1.fork returns the child's process ID
2.Using fork and pipe.
3.To retrieve the process ID for the parent process for your program, call the function getppid.
4.Distinguish between the parent and child processes
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.