Some years ago I had similar needs...
Only fork don't solve my problem because the Apache webserver shielded my process, and my process died with apache instance, whithout terminate.

After more XP I sugest to you eval a code like this:

  • Control session with cookie, ip address or mail
  • Flock to refuse multiple restart on process
  • use fork and "Daemonize" process for dissociation of child/parent.

    use CGI; use POSIX qw(setsid); use Fcntl qw(:flock); ... my $Session = ... ... without session ... deny access my $SessionFile = "/tmp/$Session"; # Touch control file unless ( -f $SessionFile ) { open(C, ">$SessionFile"); close(C) } unless ( open(F, "+< $SessionFile") ) { print $q->h1("Session control failure"); exit 1; } unless ( flock(F, LOCK_EX | LOCK_NB) ) { print $q->h1("Session locked, is running ?"); exit 1; } ... Daemonize like process ... my $pid; open STDIN, '/dev/null' or die "Can't read /dev/null: $!"; open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!"; unless ( defined($pid = fork ) ) { print $q->h1("Can't fork: $!"); exit 1; } if ( $pid ) { # I'm parent... good by to User print "Good Bye,<br>Wait for mail after process..."; exit 1; } #-- dissociate Apache CGI shell unless ( setsid ) { warn "Can't start a new session: $!"; ... mail to user warning failure ... exit 1; } ... do your process ... ... see merlyn's sugestions about sendmail ... flock(F, LOCK_UN ); close(F); exit 1;
    Code don't tested, it's my concept ideas arround your question. See other response nodes, they have good ideas and complete my node :)

    --
    Marco Antonio
    Rio-PM


    In reply to Re: Perl modules for batch web processing by mda2
    in thread Perl modules for batch web processing by srdst13

    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.