in reply to Win32: Starting and stopping processes (part 1)

In Win32 you should avoid using kill on forked processes.


perlfork - Perl's fork() emulation


The fork() emulation is implemented at the level of the Perl interpreter. What this means in general is that running fork() will actually clone the running interpreter and all its state, and run the cloned interpreter in a separate thread, beginning execution in the new thread just after the point where the fork() was called in the parent. We will refer to the thread that implements this child "process" as the pseudo-process.


=item kill()

C<kill('KILL', ...)> can be used to terminate a pseudo-process by passing it the ID returned by fork(). The outcome of kill on a pseudo-process is unpredictable and it should not be used except under dire circumstances, because the operating system may not guarantee integrity of the process resources when a running thread is terminated. The process which implements the pseudo-processes can be blocked and the Perl interpreter hangs. Note that using C<kill('KILL', ...)> on a pseudo-process() may typically cause memory leaks, because the thread that implements the pseudo-process does not get a chance to clean up its resources.

As the terminated thread runs inside the same process as the controlling thread, it is always possible that the controlling thread will get damaged by this action.

See also:

  • Comment on Re: Win32: Starting and stopping processes (part 1)