Using fork on win32 for anything other than simple uses just creates problems. On win32, fork is emulated using a thread, and exec spawns a new process running the exec'd program and the thread waits for that child process. The 'pid' you get back is a funny (negated) thread id, not a process id.

You are given no access to the process id of the spawned process, and as there is (could not be) any parent-child relationship between the thread that is spawned and the process it monitors, killing the thread via is funny thread-id doesn't kill the process.

Upshot. Using fork on win32 is fraught with problems. If you need to do it, using the forking open which returns the real pid of the forked process is usually preferrable. However, even that has problems. Unless you take care to ensure that Perl doesn't decide to run the program you asked for via a shell, you can end up with the pid of the shell rather than the program you asked to run and again, you have no access to the pid of the actual process and cannot kill it.

Historically, unlike POSIX platforms, all win32 processes were considered peers. Ie. There was no parent-child relationship between a process B start by a process A. Killing process A left process B untouched. There are now, and have been for many years, options to CreateProcess that create a hierarchal relationship between processes such that killing process A above would also terminate process B, (see the "End process tree" option on the Task Manager context menu), but Perl has never caught up in this regard.

If, as implied by your post, you are mixing threads with fork, you are in a world of hurt.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: killing on win32 by BrowserUk
in thread killing on win32 by Razvanica

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.