#!/usr/bin/perl -w use CGI qw( header ); use strict; use POSIX qw( setsid ); my $pid; # fork die "cannot fork: $!" unless defined ( $pid = fork() ); # if parent if ( $pid ) { # reply to user print header(), "Process forked."; } else { # we're the child # so we don't prevent filesystems from being unmounted chdir '/' or die "Can't chdir to /: $!"; # redirect IO, or we'll be sucky and make the CGI hang open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; # thank you, POSIX ( I'd have hated to call ioctl() myself! ;-) setsid or die "Can't start a new session: $!"; # lets wait until after setsid to redirect STDERR open STDERR, '>&STDOUT' or die "Can't dup stdout: $!"; # run our background process exec("/path/process"); }