Where is this fork you keep mentioning? Are you doing if (!fork()) { system(...) } or if (!fork()) { exec(...) }? If you do the former, you'll have two copies of the parent perl script running once the child exits.

Example use of launching an executable using fork():

# We are in the only process. printf STDERR ("pid = %d\n", $$) if $DEBUG; $pid = fork(); die("fork failed!\n") unless (defined($pid)); if (!fork()) { # We are in the child process. printf STDERR ("child pid = %d\n", $$) if $DEBUG; exec(...); # We'll never reach here if exec() worked. # Avoiding die(); we don't want eval{} catching this. print STDERR "exec failed!\n"; exit(2); } # We are in the parent. printf STDERR ("parent (pid = %d) successfully spawned child (pid = %d +).\n", $$, $pid) if $DEBUG;

Alternatively:

use Win32; use Win32::Process; sub GetLastErrorStr { return Win32::FormatMessage(Win32::GetLastError()); } my $process_obj; Win32::Process::Create( $process_obj, "bla.exe", "arg1 arg2", 0, NORMAL_PRIORITY_CLASS, "." ) || die("Error running bla.exe: " . GetLastErrorStr() . "\n"); printf STDERR ("parent (pid = %d) successfully spawned child (pid = %d +).\n", $$, $process_obj->GetProcessID()) if $DEBUG; ... $process_obj->kill(255);

By the way, in Windows, I don't think the process has a chance to shut itself down properly when told to die using kill(). If the application has a window, it's better to send WM_QUIT to the window (and kill it if that doesn't work). If it doesn't have a window, it provides some kind of API (usually a DLL call) that will shut it down. This could explain your 100% usage after killing the process.


In reply to Re: Extremely odd behavior with net::ping and fork by ikegami
in thread Extremely odd behavior with net::ping and fork by wolfger

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.