You are correct that you need to run a daemon, but I don't think there should be any problem with daemonizing in the CGI before you exec(). For example,

#!/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"); }
--4c6966653a205468652073656172636820666f
  7220746861742070657266656374204765656b
  20436869632c20746865206f6e652077697468
  2074686520737061726b6c696e672065796573
  2077686f20706c617973206973207261696e2e

In reply to Re: forking from web by Aighearach
in thread forking from web by cez

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.