Sly_G has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: fork and spoon
by Illuminatus (Curate) on Apr 03, 2011 at 00:44 UTC | |
by Sly_G (Novice) on Apr 03, 2011 at 13:55 UTC | |
Re: fork and spoon
by Illuminatus (Curate) on Apr 04, 2011 at 11:57 UTC | |
by Sly_G (Novice) on Apr 04, 2011 at 22:28 UTC |
Back to
Seekers of Perl Wisdom