in reply to Concurrent Processes
Also this bit I think is incorrect on its face:
After each fork, the parent process is going to wait for the most recently forked child to complete BEFORE the next one is forked. All of your forked processes are going to run SERIALLY not in parallel.if ($pid[$i]=fork()) { # parent process waitpid($pid[$i], 0); # wait for child close ($wh); ...
What I think you might want to try is this:
## ## launch children ## for( $i = 0 ; $i < NUMPROCS ; $i++ ) { $pid[$i] = fork() ; next if( $pid[$i] != 0 ) ; # fork next process ## ## child stuff ## exit(0) ; # when finished } ## ## gather children ## foreach( @pid ) { waitpid($_, 0) ; # waits for each child if( $? != SOMETHINGGOOD ) { # bad exit status } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Concurrent Processes
by mcogan1966 (Monk) on Oct 21, 2003 at 18:32 UTC | |
by mpeppler (Vicar) on Oct 21, 2003 at 18:37 UTC | |
by mcogan1966 (Monk) on Oct 21, 2003 at 18:48 UTC | |
by ptkdb (Monk) on Oct 21, 2003 at 18:35 UTC | |
by ptkdb (Monk) on Oct 22, 2003 at 17:03 UTC |