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

Under normal circumstances, what you've done (in particular, closing STDOUT and STDERR) should be sufficient to detach a forked CGI script.  In order to further debug the issue you could try lsof — e.g. lsof -p<PID> to show files/pipes/etc. associated with process number PID (i.e. your CGI process that presumably causes httpd to hang).

BTW, what's the exact context? Is this a regular CGI script, or called from within a mod_perl handler, or are you running the CGI script via mod_perl registry, etc.?  Is there a database involved (DBI/DBD::*)?

Replies are listed 'Best First'.
Re^2: fork/web-cgi: how do i close all open sockets in deamon?
by .rhavin (Initiate) on Jan 25, 2010 at 11:47 UTC

    thx for helping, i did what you suggested, but im not quite shure what to do with the obtained information ... i did a lsof right after forking with the pid of the child and got that:


    COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
    camtest.c 18397 web39 cwd DIR 0,23 2048 263424456 /var/www/web39/html/cgi-bin
    camtest.c 18397 web39 rtd DIR 0,23 1024 37650436 /
    camtest.c 18397 web39 txt REG 0,23 1061700 37766238 /usr/bin/perl
    camtest.c 18397 web39 mem REG 0,23 67364 38240776 /lib/tls/libresolv-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 17840 38240762 /lib/tls/libnss_dns-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 38372 38240764 /lib/tls/libnss_files-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 126656 37733628 /usr/lib/libexpat.so.1.0.0
    camtest.c 18397 web39 mem REG 0,23 19764 386252810 /usr/lib/perl/5.8.8/auto/Socket/Socket.so
    camtest.c 18397 web39 mem REG 0,23 96276 37749838 /usr/lib/perl5/auto/XML/Parser/Expat/Expat.so
    camtest.c 18397 web39 mem REG 0,23 111304 110919694 /usr/lib/perl/5.8.8/auto/POSIX/POSIX.so
    camtest.c 18397 web39 mem REG 0,23 32664 236503042 /usr/lib/perl/5.8.8/auto/Encode/Encode.so
    camtest.c 18397 web39 mem REG 0,23 21868 38240738 /lib/tls/libcrypt-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 1245488 38240734 /lib/tls/libc-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 85010 38240774 /lib/tls/libpthread-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 145136 38240754 /lib/tls/libm-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 9592 38240752 /lib/tls/libdl-2.3.6.so
    camtest.c 18397 web39 mem REG 0,23 15640 386301956 /usr/lib/perl/5.8.8/auto/IO/IO.so
    camtest.c 18397 web39 mem REG 0,23 88164 38240648 /lib/ld-2.3.6.so
    camtest.c 18397 web39 0r REG 0,23 12980 376176656 /usr/share/perl5/HTTP/Request/Common.pm
    camtest.c 18397 web39 1u IPv4 3040810374 UDP server2.alido.de:44066->ns1.vpsadmin.de:domain
    camtest.c 18397 web39 3w REG 0,23 1554 263423062 /var/www/web39/html/cgi-bin/test.err
    camtest.c 18397 web39 4w FIFO 0,7 3040810341 pipe

    is 'device 3040810374' the handle i look for? how can i close it? i dont have mod_perl, its a cgi-scipt w/o any open db.

      I *think* i found it .. /var/www/web39/html/cgi-bin/test.err is the carp-out ... after commenting out the carping, it worked ... so the deamon just has to close that handle, too. Thanks for helping in getting the answer.