Tutorials Point


  Perl Home

  PERL Functions

© 2011 TutorialsPoint.COM


  Home     References     About TP     Advertising  

PERL fork Function



Syntax

fork


Definition and Usage

Forks a new process using the fork( ) system call. Any shared sockets or filehandles are duplicated across processes. You must ensure that you wait on your children to prevent "zombie" processes from forming.

Return Value

  • undef on failure to fork

  • Child process ID to parent on success 0 to child on success

Example

Following are the usage...

#!/usr/bin/perl

$pid = fork();
if( $pid == 0 ){
   print "This is child process\n";
   print "Chile process is existing\n";
   exit 0;
}
print "This is parent process and child ID is $pid\n";
print "Parent process is existing\n";
exit 0;

#This will produce following result

This is parent process and child ID is 16417
Parent process is existing
This is child process
Chile process is existing



Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names