Main.pl -> parent process
use strict;
use warnings;
use function;
use Win32::Process;
use constant
ABOVE_NORMAL_PRIORITY_CLASS => 0x00008000;
my
$cmd="C:\\windows\\system32\\cmd.exe";
my $params = "cmd.exe /c
perl.exe C:\\Dropbox\\Pet_Projects\\perl_process\\process.pl";
my $startFolder = shift || q{.};
my $procobj;
print "\n before calling the
child process \n";
#Creates a process with the
command and the params and flags
Win32::Process::Create(
$procobj,$cmd, $params, 0,CREATE_NEW_CONSOLE| ABOVE_NORMAL_PRIORITY_CLASS ,
$startFolder );
$procobj->Wait(INFINITE);
-> wait for child to complete
print "\n after calling the
child process \n";
Process.pl -> child process
use strict;
use warnings;
use function;
for (my $i =0;$i < 120;$i++) {
sleep
5;
print_name();
}
Return;
Function.pm -> Header file creates the package and exports the
functions
use strict;
use warnings;
package function;
use Exporter;
our @ISA = 'Exporter';
our @EXPORT = qw( print_name );
my $name = "surendra patil
";
sub print_name {
print
"\n Name:- $name \n";
}
1;
Output
First window is parent process,
which creates the child process in new window and waits for the completion of the
child process.
Flags used: - Different flags can be combined to handle the
child process differently.
CREATE_NEW_CONSOLE -> Run
child process in new console window
ABOVE_NORMAL_PRIORITY_CLASS ->
increase the priority of the process
Comments