close a filehandle for all processes
close a filehandle for all processes
am 24.12.2007 09:19:21 von himanshu.garg
Hello,
I have a process that opens a filehandle and after forking a
child closes the filehandle. The child can be used to run an arbitrary
command and I cannot do anything there.
Is there a way I can do a close for all the processes not just
the parent. Some equivalent of a shutdown for sockets?
Thank You,
HG
Re: close a filehandle for all processes
am 24.12.2007 16:38:53 von nobull67
On Dec 24, 8:19 am, himanshu.g...@gmail.com wrote:
> I have a process that opens a filehandle and after forking a
> child closes the filehandle. The child can be used to run an arbitrary
> command and I cannot do anything there.
>
> Is there a way I can do a close for all the processes not just
> the parent. Some equivalent of a shutdown for sockets?
Your question has nothing to do with Perl.
As far as I know there is no such feature in the POSIX-like standards.
Note you can close() handles in the child process between the fork()
and the exec() if you are willing to operate at the lower level.
You can also set the close-on-exec flag on a file descriptor. See the
$^F special variable.
Note that by default all descriptors other than 0,1,2 will be have the
close-on-exec() property anyhow so this is likely to be an non-issue
anyhow.
Re: close a filehandle for all processes
am 28.12.2007 05:13:22 von himanshu.garg
On Dec 24, 8:38 pm, Brian McCauley wrote:
> On Dec 24, 8:19 am,himanshu.g...@gmail.com wrote:
>
> > I have a process that opens a filehandle and after forking a
> > child closes the filehandle. The child can be used to run an arbitrary
> > command and I cannot do anything there.
>
> > Is there a way I can do a close for all the processes not just
> > the parent. Some equivalent of a shutdown for sockets?
>
> Your question has nothing to do with Perl.
:) I realized this shortly after sending the original post.
>
> As far as I know there is no such feature in the POSIX-like standards.
>
> Note you can close() handles in the child process between the fork()
> and the exec() if you are willing to operate at the lower level.
>
> You can also set the close-on-exec flag on a file descriptor. See the
> $^F special variable.
The scenario that I am in requires that I close the filehandles only
when the immediate child has died. Since this is the one execed and it
can be arbitrary command, close on exec may not work here.
>
> Note that by default all descriptors other than 0,1,2 will be have the
> close-on-exec() property anyhow so this is likely to be an non-issue
> anyhow.
I see. This could be useful.
Thanks,
HG
Re: close a filehandle for all processes
am 28.12.2007 12:19:59 von Joost Diepenmaat
himanshu.garg@gmail.com writes:
> On Dec 24, 8:38 pm, Brian McCauley wrote:
>> On Dec 24, 8:19 am,himanshu.g...@gmail.com wrote:
> The scenario that I am in requires that I close the filehandles only
> when the immediate child has died. Since this is the one execed and it
> can be arbitrary command, close on exec may not work here.
So you want to close the file-handle in the parent, when the child
dies? It will already be closed in the child, since when a process exits
all its handles are closed.
In that case you may be able periodically check if the child PID still
exists, or you can use SIGCHLD or system() or `` etc to get notified
automatically when the child process ends.
Joost.