On Fri, 15 Dec 2000, Kees Vonk 7249 24549 wrote:
> Stas writes:
> > How about
> >
> > close STDOUT;
> > close STDIN;
> > close STDERR;
> >
> > in your child code?
> >
> > check this out:
> >
> > http://perl.apache.org/guide/performance.html#Forking_and_Executing_Subprocess
> >
> > it's explained there.
>
>
> I have tried closing STDOUT, STDIN and STDERR, but that
> doesn't make any difference.
>
> What I do at the moment is:
>
> 1. Start the long running process (runs indefinitly for the
> purpose of this test), which closes STDOUT, STDIN and
> STDERR and then calls setsid().
Why do you call setsid()?
Are you spawning a process with shell or fork?
* If you spawn the process with fork remove setsid() and it'll work.
* If you spawn the process with ``/system it works with what you've
described.
I've tested both on my machine.
> I think the following might be the solution, we have done
> that in a (not internet related) C program here to solve
> almost the same problem.
>
>
> Vivek writes:
>
> > KV72> Has anyone got an idea how to get around this? Can I get to
> > KV72> the inherited socket connection and close it when I have
> > KV72> detached from the calling process?
> >
> > After you fork, why not close all open file descriptors you are not
> > using?
What Vivek meant I suppose is the same: STDOUT and STDIN.
> I have had a look throught the camel book. How do I close a
> file descriptor (or find out if it is open), the perl close
> function only accepts file handles.
% perldoc -q descriptor
Found in /usr/lib/perl5/5.6.0/pod/perlfaq5.pod
How do I close a file descriptor by number?
This should rarely be necessary, as the Perl close()
function is to be used for things that Perl opened itself,
even if it was a dup of a numeric descriptor, as with
MHCONTEXT above. But if you really have to, you may be
able to do this:
require 'sys/syscall.ph';
$rc = syscall(&SYS_close, $fd + 0); # must force numeric
die "can't sysclose $fd: $!" unless $rc == -1;
Or just use the fdopen(3S) feature of open():
{
local *F;
open F, "<&=$fd" or die "Cannot reopen fd=$fd: $!";
close F;
}
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://apachetoday.com http://logilune.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/