home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / perl / 7377 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.8 KB  |  55 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!malgudi.oar.net!chemabs!jon
  3. From: jon@cas.org (Jon Vander Hill)
  4. Subject: Re: timing problem with $SIG{'CHLD'}
  5. In-Reply-To: ccechk@nuscc.nus.sg's message of Fri, 11 Dec 1992 07:33:01 GMT
  6. Message-ID: <JON.92Dec12073444@cas.org>
  7. Sender: usenet@cas.org
  8. Organization: Chemical Abstracts Service, Columbus, Ohio
  9. References: <1992Dec7.112748.24164@hemlock.cray.com> <1992Dec11.073301.29314@nuscc.nus.sg>
  10. Date: Sat, 12 Dec 1992 12:34:44 GMT
  11. Lines: 42
  12.  
  13. >>>>> On Fri, 11 Dec 1992 07:33:01 GMT, ccechk@nuscc.nus.sg (Heng Kek) said:
  14.  
  15. > mlo@cray.com (Mick Oyer) writes:
  16. > : I'm trying to set up a daemon, written in perl, that will listen
  17. > : for messages coming across the network.  I used the client/server
  18. > : model in the Camel book as a starting point, but am running into
  19. > : a sticky situation.
  20. > : 
  21. > [..deleted..]
  22. > : I'm setting $SIG{'CHLD'} to reap the zombies.
  23. > : The problem:
  24. > : my code is blocking on the 'accept' call.  When the child
  25. > : exits, the CHLD signal causes reaper to get called, interfering
  26. > : with the accept:
  27. > :     Interrupted system call at ./modinfod line 45.
  28. > : 
  29. > :     (line 45):    ($addr = accept(NS,S)) || die $!;
  30. > : 
  31.  
  32. > I had EXACTLY the same problem.  My work-around was to re-invoke
  33. > 'accept()' when it dies as per the problem above.  I use:
  34.  
  35. >   ($addr = accept(KK,S)) || ($addr = accept(KK,S)) || 
  36. >                              die "accept:$!\n";
  37. >             # ..to avoid accept() dying and killing the prog.
  38.  
  39. > Any criticism on this method is most welcome as I'd like to learn
  40. > too.
  41.  
  42. Here's an alternative approach:
  43.  
  44. for(;;) {
  45.     $addr = accept(NS,S);
  46.     if (!defined $addr) {
  47.     next if $! =~ /^Interrupted/;
  48.     die "$0: accept failed: $!\n";
  49.     }
  50.     ...
  51. }
  52.  
  53. Jon Vander Hill
  54. jon@cas.org
  55.