Perl Process Management

You are free to use various ways to create new process in perl. Here are the following points to keep in mind

  • Every process is created using any of the mentioned methods, maintains its own virtual environment with-in %ENV special variable
  • You can use $$, special variable, to get the current process ID
  • You can also use $PROCESS_ID, special variable to get current process ID
  • All the open handles are dup()-ed in the child-processes, so that closing any handles in one process doesn't affect others
  • The function named exit() always exits just the child process which executes this function and the main process as a whole will not exit unless all the running child-processes have been exited

Perl Process Management Example

Let's take a look at the following example:


@files = `ls -l`;

foreach $file (@files){
   print $file;


When the above perl program is executed, it lists all the files and directories present inside the current directory:

drwxr-xr-x 3 root root 4096 Sep 14 06:46 9-14
drwxr-xr-x 4 root root 4096 Sep 13 07:54 android
-rw-r--r-- 1 root root  574 Sep 17 15:16 index.htm
drwxr-xr-x 3  544  401 4096 Jul  6 16:49 MIME-Lite-3.01
-rw-r--r-- 1 root root   71 Sep 17 15:16
drwx------ 2 root root 4096 Sep 17 15:11 vAtrJdy

Perl Online Test

« Previous Tutorial CodesCracker Home »