Suppose I made updater-script that daemonizes itself like this:
sub Daemonize { return if ($^O eq 'MSWin32'); chdir '/' or die "Can't chdir to /: $!"; umask 0; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to '>/dev/null': $!"; open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!"; defined(my $pid = fork) or die "Can't fork: $!"; exit if $pid; setsid or die "Can't start a new session: $!"; if (-e '/www/run/update_selena.pid') { die "Process is running" } open PID, '>/www/run/update_selena.pid' or die "Can't write pid: $!" +; print PID $$; close PID; }

It does it ok, if I run it from command line.

Then I made a script-manager for several updater-scripts like this (all of them are supposed to run independently for long periods of time). Manager should be able to run them, to show us if particular updater is running or not, and to kill running updaters (using pid files they're saving for themselves).

So, when I try to run such an updater from a manager, the latter hangs and waits until updater is done. Which is not what I inteded. No matter if I use backticks or system().

What is it that I'm doing wrong? Please, help.


In reply to fork and spoon by Sly_G

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.