#!/usr/bin/env perl # daemon - daemonize a process that doesn't know how to daemonize itself # Andrew Ho (andrew@zeuscat.com) require 5.6.0; use warnings; use strict; use POSIX qw(setsid); use File::Basename qw(basename); use constant ME => basename $0; use constant USAGE => sprintf "usage: %s prog [args]\n", ME; die USAGE unless @ARGV; my $pid = fork; exit if $pid; die sprintf "%s: could not fork: %s\n", ME, $! unless defined $pid; setsid or die sprintf "%s: could not start new session: %s\n", ME, $!; close STDIN; close STDOUT; close STDERR; exec @ARGV; die sprintf "%s: should never reach this line\n", ME;