Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Disclaimer

The following note applies to unix-like system calls only. My mojo does not apply to windows.

As tye apparently explained to you, most SysV-style (and by exension, linux) system calls are interruptible. The wait(2) and waitpid(2) calls are examples.

Since your database connection to MySQL needs to use sockets to communicate with the database, you may receive signals (SIGPOLL is common with asynchronous I/O, for example). Likewise, if you have a second process in the background, it can send a SIGCLD when it exits. And timers send SIGALRM.

The fun part of this is that Unix only stacks one of each signal for calls to the handler -- so your signal handler might only get called once even when two processes die. This doesn't just apply to $SIG{FOO} handlers, it also applies to the implicit handler in wait() calls. I haven't (yet) walked the Perl source to satisfy my curiosity, but I expect that since it uses waitpid(), it's trapping that case reasonably well.

Some test cases I ran using system() and alarm() shows that the $! value sometimes (but not always) gets set to "interrupted system call" when this occurs. It depends on where you are in the system call when the signal arrives, I think. In any event, my general rule is to trust the value of ( $? >> 8 ), which gives the return status of the child process. YMMV, especially if you were to create more than one child process -- i don't know which one would end up in $?.

I have definitely seen the case where the signal arrives and the child process continues running to completion long after the return code is "returned." In C, I avoid the whole thing by calling popen() and reading until end-of-file. I don't know if you can apply that technique to wget in perl using open my $fh, '-|', $cmd or not.


In reply to Re: System call + signals = bad return code? by papidave
in thread System call + signals = bad return code? by swkronenfeld

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? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2023-01-29 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?