perl daemonize
* 참고링크
http://deadfire.hihome.com/perl/perl029.html
http://vozlt.tistory.com/28
* 사용법
HTTP request sent, awaiting response... 200 OK
Length: 838 [text/plain]
Saving to: `daemon'
100%[=====================================================>] 838 --.-K/s in 0s
2012-07-23 15:59:06 (114 MB/s) - `daemon' saved [838/838]
[root@zenoss tmp]# mv daemon daemon.pl
[root@zenoss tmp]# chmod 700 daemon.pl
[root@zenoss tmp]# ./daemon.pl 프로그램이름
#! /usr/bin/perl
use POSIX;
use strict; use warnings;
if ($#ARGV != 0) { die "You have to Input argument only one"; }
print "First Argument: $ARGV[0]\n" if defined $ARGV[0];
if ($ARGV[0] !~ "/") { die "You have to Input PATH + PROGRAM_NAME"; }
local $| = 1; # autoflush
# daemonize run
daemonize();
# 데몬화후 구문들...
while(1) {
system("$ARGV[0]");
sleep(5);
}
# perl daemonize function
sub daemonize {
my $_PATH_DEVNULL = "/dev/null";
my $pid = fork();
if ($pid > 0) {
exit(0);
}
umask(0);
POSIX::setsid() or die "POSIX::setsid() : $!";
chdir('/') or die "chdir() : $!";
open(STDIN, '/dev/null') or die "STDIN : $!";
open(STDOUT, '>>/dev/null') or die "STDOUT : $!";
open(STDERR, '>>/dev/null') or die "STDERR : $!";
}