Hi,
Thank you for your post.
As far as I know, Windows doesn't seem to have this mechanism. I can't confirm Perl. For your issue, I suggest that you could post it to github forum. It's a right place you could get more help. Thank you for your understanding.
https://github.com/BorisSchaeling/boost-process/issues/13
Hope this helps and please help to accept as Answer if the response is useful.
Best Regards,
Carl
How to keep child process active when parent is killed/finished (in windows)
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
}
What can be the solution in windows?
Please provide assistance in implementing the same logic in windows using Perl.
Thanks!
1 answer
Sort by: Most helpful
-
Carl Fan 6,836 Reputation points
2021-07-08T09:32:46.04+00:00