I have written a cgi script that needs some temporary files. Since the file needs to be passed off to a back-end executable, I cannot simple create the file and then unlink it to be sure the disk space is freed when the process dies.

I wrote a simple temporary file module that creates a unqiue temporary directory and then creates the temporary files inside. I used and END block to make sure the files where deleted when the script ended or died.

The problem is that it some cases, the END block is not executed and the files remain. When this first happened, I realized it was a result of the user stopping the http connection. A TERM or PIPE signal is sent to the cgi process.

I started installing signal handlers to catch the signals.

This has not completely solved the problem. In some cases, the http connection times out. The cgi process ends, but the END block in the temporary module is not executed. I tried installing signal handlers for all signals, but it did not help.

Does anyone know what happens to a cgi process when the http connection times-out? The web server in Apache on Linux.


In reply to CGI Perl Script fails to clean-up by Anonymous Monk

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.