in reply to Nested forks -help!

The code you posted runs exit ("this exits child process at customer level") in both child and parent on the outer loop! If you don't ignore SIGCHLD but instead wait for the child to finish, it "works", as long as @customers <= 1. But are you sure it ever starts a second "customers" process with this code? It would appear to spawn (at most) one, then terminate.

Other than that, what exactly happens when you say "Perl seems to be confusing which child belongs to which parent or something of the kind"? None of your parents seem to take any heed of their children!

Replies are listed 'Best First'.
Re: Re: Nested forks -help!
by Anonymous Monk on Jul 23, 2001 at 19:50 UTC
    you're right, the exit call at customer level is wrong, it should be at the end of the
    if ($cust_pid == 0) {
    }
    section. And this is where it is in my application. Sorry for not spotting the typo in my message before submitting it.
    I need multiple customers running at the same time so I can't wait for the child to finish unfortunately.

    What I mean by "Perl seems to be confusing...." is that the Net::SNMP module starts giving me strange errors in the form of "No response from Agent on router" and "Sent pid is not the same as the one received", whereas when I omit forking at customer level, I do not get any errors at all.

    I read somewhere that SIGCHLD is not very reliable with Perl and that race conditions could occur. Can it be just that the source of my problem?

      Unfortunately I'm unfamiliar with the Net::SNMP module and the SNMP protocol, so I shan't be able to help much.

      I read somewhere that SIGCHLD is not very reliable with Perl and that race conditions could occur. Can it be just that the source of my problem?
      Not if $SIG{CHLD} is indeed set to 'IGNORE' in your program.

      One possibility for getting into troubl with multiple processes is to try to use them same socket with all of them. This will probably happen if you create your Net::SNMP session in advance for all your children and try to use it from all of them; either create a separate object in each (leaf!) child or put all uses of the session inside mutexes.