sub Daemonize() { my $pid; $pid=fork(); if(! defined($pid) ){ #Forking Failed, we exit at this point die("forking failed\n"); exit(1); } if ($pid>0) { print LOG "Forking Success. Child PID: $pid \n"; exit(); } $|=1; print LOG "Child Process Executing... \n"; setsid(); chdir('/'); umask(0); close(STDIN) ; close(STDOUT) ; close(STDERR) ; }