I have done a similar thing to what you describe. Although I have never used open3. I always use Win32::Process to spawn my "children" processes. Below is some code I ripped from some production code which launches several process that all have the same NAME but will obviously have different PIDS. I have to keep the PIDS in an array, each process that I launch also has some kind of unique identifier.

foreach my $md (@chk_mds) { #@chk_mds is a list of the unique ident +ifiers (I.e SrvA, SrvB, SrvC etc) #Read What Kind of Process to Start. if (!&Spawn($md)) { &Update_Log("Problems Spawning $proc[0] Process for $md"); } sleep(1); } #Re-Spawn the broken Process sub Spawn { my $rc = 0; my $md = shift; my $result = Win32::Process::Create( $ProcessObj, "$xcall_path/bin/application.exe", "application.exe $md", 1, #Inherit Handles. NORMAL_PRIORITY_CLASS, ".") or &Update_Log("DEBUG - Cannot Launch the X-$ +proc process: $!"); if ($result) { my $pid = $ProcessObj->GetProcessID(); $proclst{$md} = $pid; push (@pids, $pid); &Update_Log("\@pids = @pids"); &Update_Log("Launching Call Logger Process for $md with PI +D - $proclst{$md}"); $rc = $pid; } else { &Update_Log("Process for $md NOT successfully Created:" . +Win32::FormatMessage(GetLastError())); } return($rc); } #Update Log file sub Update_Log { my ($ss, $mm, $hh, $d, $mon, $yr) = localtime(); my $date = sprintf("%02d-%02d-%04d", $mon+1, $d, $yr+1900); my $time = sprintf("%02d:%02d:%02d", $hh, $mm, $ss); #Specify the Logfile Name my $logfile = "$xcall_path/log/X-CallServer$date.log"; if (open( LOG, ">>$logfile" ) ) { my $TempSelect = select( LOG ); $| = 1; select( $TempSelect ); if (! $_[0]) { return (0); } print LOG "$time - $_[0]"; } else { &Event(EVENTLOG_ERROR_TYPE, "X-CallServer Could Not Open Logfi +le $logfile: $!"); exit(5); } close(LOG); return(1); }

So what I have is a hash (%proclst) of all my application.exe's PIDS. I then have a piece of code that kills these PIDS when the service stops.

foreach my $pid (keys %proclst) { Win32::Process::KillProcess($proclst{$pid}, 255); &Update_Log("Service Stopping - Stopping $proclst{$pid}"); } undef %proclst;
These are only snippets from a larger piece of code, I am using Win32::Daemon for all my service requirements on Win32 also. The Update_Log is a routine that I use to update log files etc.. Really only included so you dont get confused when you see me call it from the Spawn function.

HTH..

-----
Of all the things I've lost in my life, its my mind I miss the most.

In reply to Re: kill a child / parent process by AcidHawk
in thread kill a child / parent 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.