in reply to background w/out fork?

Why would you need to rewrite the application? Just prepend "fork and exit".
fork and exit; my $old_code;
(Actually theres some other stuff you should theoretically do, like setsid or something from posix, but none of that should involve rewriting your script. Just prepend it.)

Replies are listed 'Best First'.
Re^2: background w/out fork?
by tachyon (Chancellor) on Jul 01, 2004 at 01:25 UTC

    Something like this is a standard way to daemonize a process:

    use POSIX qw(setsid); defined(my $pid = fork) or die "Can't fork: $!"; exit 0 if $pid; chdir '/' or die "Can't chdir to /: $!"; umask 0; setsid() or die "Can't start a new session: $!"; print "Started $0 daemon OK\n\n"; # now finish of by redirecting I/O stuff # we want to ignore STDIN open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; # send STDOUT, STDERR wherever... open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!";

    cheers

    tachyon