Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Your script is horrible to read, it's prone to creating zombie processes and it doesn't even compile.

So, no, you're not doing it properly.

I was hoping that some other monk would tell you that more politely, but no one did, so I'm just telling you like it is.

As for what is wrong: $output and $fver are not declared anywhere, so use strict aborts compilation. wait in a SIGCHLD handler is just wrong, because it waits only for one child, but:

... when the signal is delivered to the process by the system (to the C code that implements Perl) a flag is set, and the handler returns immediately.
    Then at strategic "safe" points in the Perl interpreter (e.g. when it is about to execute a new opcode) the flags are checked and the Perl level handler from %SIG is executed.
        As the Perl interpreter looks at signal flags only when it is about to execute a new opcode, a signal that arrives during a long-running opcode (e.g. a regular expression operation on a very large string)  will not be seen until the current opcode completes.
        If a signal of any given type fires multiple times during an opcode  (such as from a fine-grained timer), the handler for that signal will be called only once, after the opcode completes; all other instances will be discarded.
In addition, the flag-setting handler in perl blocks SIGCHLD signal while it's executing; and only one blocking signal can be pending, so, if two or more children die during that, you'll get at least one zombie.

Recommended fix:

Recommended reading:
perldoc perlstyle perldoc strict perldoc perlipc man 7 signal man 2 wait man 2 sigaction perldoc -f wait perldoc -v '%SIG'
Also, see "The Linux Programming Interface", chapters 20-22 (applicable to all Unix-like systems, not only Linux).

In reply to Re: Im I forking properly ? by Anonymous Monk
in thread Im I forking properly ? by leostereo

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?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-05-21 17:18 GMT
Find Nodes?
    Voting Booth?

    No recent polls found