# We are in the only process. printf STDERR ("pid = %d\n", $$) if $DEBUG; $pid = fork(); die("fork failed!\n") unless (defined($pid)); if (!fork()) { # We are in the child process. printf STDERR ("child pid = %d\n", $$) if $DEBUG; exec(...); # We'll never reach here if exec() worked. # Avoiding die(); we don't want eval{} catching this. print STDERR "exec failed!\n"; exit(2); } # We are in the parent. printf STDERR ("parent (pid = %d) successfully spawned child (pid = %d).\n", $$, $pid) if $DEBUG; #### use Win32; use Win32::Process; sub GetLastErrorStr { return Win32::FormatMessage(Win32::GetLastError()); } my $process_obj; Win32::Process::Create( $process_obj, "bla.exe", "arg1 arg2", 0, NORMAL_PRIORITY_CLASS, "." ) || die("Error running bla.exe: " . GetLastErrorStr() . "\n"); printf STDERR ("parent (pid = %d) successfully spawned child (pid = %d).\n", $$, $process_obj->GetProcessID()) if $DEBUG; ... $process_obj->kill(255);