I was actually creating a script in which fork()
creates a child process that runs in the background, and checks the time period of the main script (parent process), running in the foreground, using its process ID. If the main script (parent process) exceeds the threshold time, then action/s would be taken.
In Linux, it got implemented because of the INIT process that becomes the parent of the active child process (orphaned process) after the main script(parent) is killed or finished.
But, I am not able to implement it in Windows, as parent-child architecture is different from Linux.
Short code for the same (in Linux) under Perl language is:
sub run_sleep {
my $pid = fork(); ## Here, $pid var. will have child process PID for parent, and value 0 for child process
return if $pid; # returns to the parent process( out of function)
print "Running child process\n"; # Proceeds for the child process
select undef, undef, undef, $initial_time_wait ;
if ( kill 0, $Parent_ID ) { ##Here, $Parent_ID is main script id (parent process id)
print "Parent process $Parent_ID_or_script_id still exists\n";
}
else {
print "Parent process $Parent_ID_or_script_id must have completed";
exit 0;
}
print "Done with child process\n";
exit 0; # end child process
}
How to implement this for Windows?