Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Main program exits even before the child process completes on windows

by cdarke (Prior)
on Sep 01, 2011 at 14:30 UTC ( [id://923639]=note: print w/replies, xml ) Need Help??


in reply to Main program exits even before the child process completes on windows

Which OS are you running on? I ask because sometimes try to use fork/exec on Windows, and it doesn't do what they expect.

Assuming Linux/UNIX, then you could check the PID returned from wait, rather than just looking for -1, and track which child processes are ending, and what their exit code is ($?).

You do not show any error handling, maybe because it is only a code fragment, but if fork returns undef then it failed (usually because too many processes are running) and exec should not return, so the exit should be reporting an error ($!).

Then again, someone could be killing the parent, did you check its exit code?

Update: Opps! I did not read the title correctly, you are using Windows. fork creates a new thread on windows, and exec spawns a new process, so your exit is probably closing down the main process.
  • Comment on Re: Main program exits even before the child process completes on windows

Replies are listed 'Best First'.
Re^2: Main program exits even before the child process completes on windows
by vivekarcot (Initiate) on Sep 02, 2011 at 05:25 UTC

    Thanks for the reply. But even without exit, i face the same issue.

    Even if i use threads instead of fork, my main program exits even though the threads have not finished. I am not very well with debugging efforts in perl. With threads, the code looks something like this.

    my @threads;

    for ( my $count = 1; $count <= 10; $count++) {

    my ( $lines,@cnArray) = getLineCount($count);

    my $t = threads->create(\&sub1, $count, $lines, \@cnArray);

    push(@threads,$t);

    }

    foreach my $thr_num (@threads) {

    while ($thr_num->is_running()) {

    sleep(10);

    }

    if ($thr_num->is_joinable()) {

    $thr_num->join();

    }

    }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://923639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-19 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found