Win32 handles can be passed between processes in a number of ways. The easiest is to make sure the handle is inheritable. The second process should be a child of the first, and make sure InheritHandles is set to TRUE. The handle itself can be passed on the command-line.

The second method is using the Win32 API DuplicateHandle, which can pass handles between unrelated processes. Although the API for DuplicateHandle looks straightforward there are concurrency issues that you have to be careful with - this is BrowserUK's comment about storing a handle when the owning process has ended. You also have to figure out an IPC mechanism to pass the handle (which is just an unsigned int) from one process to the other.

That might sound like I am contradicting BrowserUK above, but I'm not. You are using Win32::Process which returns a Perl reference to a process object - it does not expose the handle. This Perl reference cannot be shared between processes. You will have to find another mechanism.

One alternative is to pass the PID to the second script, and then open your own process object using Win32::Process::Open. Sounds easy? There is a possible race condition. The problem is that if the child process ends while all this is going on, the next process to start might use the same PID (PIDs are reused on Windows), then you end up waiting on the wrong process. You might have to check you are waiting on the right one.

In reply to Re: Use another script to check bacground process by cdarke
in thread Use another script to check bacground process by Anonymous Monk

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.