Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-24 05:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found