...when I saw your initial code, I thought I could see what was going wrong, based upon my guess about your intention. And that has been well addressed.

What also occurred to me is that there is a good reason to use the "fork && exit" approach you started with. I've seen this well used in the creation of a bare-bones web server written in Perl.

The algorithm worked like this:

*) Parse command-line and exit if there are errors *) Read config file and exit if there are errors *) fork && exit # so that the... Parent dies Child continues in background acting as a server

...to put it another way, it's a cheap approach to backgrounding a server (or daemon) process.

I didn't get that this was something you wanted to do, but you might want to experiment with that approach to see what it does for you. Taking into account the other things that have been explained here, you might find that this adds another tool to your bag 'o tricks.

So that you get a complete understanding of the experiment, you will want to observe the processes that get created and ask yourself a few questions.

Have some fun with the variations in this strategy and decide whether this will serve you in one of your future programming tasks. But mostly have fun!

...All the world looks like -well- all the world, when your hammer is Perl.
---v


In reply to Re: fork() && exit; by agentv
in thread fork() && exit; by onegative

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.