Solved Question - Working Solution:

In order to spawn a deamon from cgi, all filehandles must get closed to completely detach from httpd. In this case, carpout'ing error log shiftet the original (and therefore still open) STDERR to CGI::Carp::SAVEERR and had to get closed also.

# ------------------------------------------------ # spawn completely detached deamon sub BaseForkDeamon { return 1 if (fork()); POSIX::setsid(); close STDOUT; close STDIN; close STDERR; close CGI::Carp::SAVEERR; # <-- close LOG return 0; };

Original Question

Hello monks... after reading for 3h thru google i still got no clue how to solve this problem ... or at least: how to do it in perl;-)

It's like this: # ------------------------------------------------ # spawns a deamon sub ForkDeamon { return 1 if (fork()); POSIX::setsid(); close STDOUT; close STDIN; close STDERR; return 0; };

That fn should fork a deamon and detach it from the calling browser in a web/cgi-skript. the problem is: it still blocks the handling httpd.
What i did understand from reading (belive to understand?) is that on fork *all* handles become copied and so my deamon still has the ports open socket. So my next try would be to close that socket and i did some googling for 'perl get port handle', because i also dont know how to obtain the HANDLE for the already open PORT and to make things a litle bit worser (at least for a non-native-speaker like me), 'port' is not a very specific search-word (i dont want to get info about how to port from/to perl) and what i really want to do is something like 'please close ALL currently open handles' - but i dont know how to do that either;-)

So, a solution for my problem would be ... nice.

The webserver of my ISP runs Apache/2.2.3 (Debian), the only Apache modules for perl i have are Apache::SOAP and Apache::XMLRPC::Lite.

thx,
~.rhavin;)

PS: should i have infringed some well known rules here, please bear in mind: it's my first posting...;-/


In reply to fork/web-cgi: how do i close all open sockets in deamon? by .rhavin

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.