File desciptors and PARENT and CHild - Unix
This is a discussion on File desciptors and PARENT and CHild - Unix ; What will happen within a parent process when a child process closes a
file descriptor inherited across a fork?...
-
File desciptors and PARENT and CHild
What will happen within a parent process when a child process closes a
file descriptor inherited across a fork?
-
Re: File desciptors and PARENT and CHild
Sanchit wrote:
> What will happen within a parent process when a child process closes a
> file descriptor inherited across a fork?
In the parent nothing will happen (well, nothing that the parent would
notice), in the child that fd will be closed.
Bye, Jojo
-
Re: File desciptors and PARENT and CHild
Sanchit writes:
> What will happen within a parent process when a child process closes a
> file descriptor inherited across a fork?
Generally, nothing.
-
Re: File desciptors and PARENT and CHild
On Mar 13, 4:47 pm, Rainer Weikusat wrote:
> Sanchit writes:
> > What will happen within a parent process when a child process closes a
> > file descriptor inherited across a fork?
>
> Generally, nothing.
I disagree.. because i know that
"When a child process moves forward in a file, the parent process will
also find itself at the new position"
So why not when a child closes its fd(file descriptor).. parent fd is
also closed as both share same fd (which are inherited in fork)!
-
Re: File desciptors and PARENT and CHild
Sanchit writes:
> On Mar 13, 4:47 pm, Rainer Weikusat wrote:
>> Sanchit writes:
>> > What will happen within a parent process when a child process closes a
>> > file descriptor inherited across a fork?
>>
>> Generally, nothing.
>
> I disagree..
'Disagreeing' with facts is completely pointless.
> because i know that "When a child process moves forward in a file,
> the parent process will also find itself at the new position"
Parent and child each have a descriptor refering to the same 'open
file structure' ...
> So why not when a child closes its fd(file descriptor).. parent fd is
> also closed as both share same fd (which are inherited in fork)!
.... because this 'open file structure' remains 'an open file
strucutre' until all of its users have stopped using it.
-
Re: File desciptors and PARENT and CHild
Sanchit writes:
>On Mar 13, 4:47 pm, Rainer Weikusat wrote:
>> Sanchit writes:
>> > What will happen within a parent process when a child process closes a
>> > file descriptor inherited across a fork?
>>
>> Generally, nothing.
>I disagree.. because i know that
>"When a child process moves forward in a file, the parent process will
>also find itself at the new position"
They share a seek pointer, but the filedescriptor is unique.
>So why not when a child closes its fd(file descriptor).. parent fd is
>also closed as both share same fd (which are inherited in fork)!
Because that's not how it's defined to work (and it would be really
awkward because you don't want to lsoe filedescriptors just because some
other process closes them (starting a child process usually involves
closing filedescripts in the child that you want to keep in the parent)
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
-
Re: File desciptors and PARENT and CHild
On Thu, 13 Mar 2008 05:39:12 -0700,Sanchit wrote:
> On Mar 13, 4:47 pm, Rainer Weikusat wrote:
>> Sanchit writes:
>> > What will happen within a parent process when a child process closes
>> > a file descriptor inherited across a fork?
>>
>> Generally, nothing.
>
> I disagree.. because i know that
> "When a child process moves forward in a file, the parent process will
> also find itself at the new position"
What do you mean by saying "moves forward"? lseek?
IIRC, lseek in child process doesn't affect the parent process.
>
> So why not when a child closes its fd(file descriptor).. parent fd is
> also closed as both share same fd (which are inherited in fork)!
If so, how can the parent know that fd is closed by its child?
--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
-
Re: File desciptors and PARENT and CHild
WANG Cong writes:
>What do you mean by saying "moves forward"? lseek?
>IIRC, lseek in child process doesn't affect the parent process.
It does (on file descriptors resulting from the same open, including
those created with dup, fork, inherited across exec, etc.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
-
Re: File desciptors and PARENT and CHild
On Thu, 13 Mar 2008 15:27:17 +0000,Casper H.S. Dik wrote:
> WANG Cong writes:
>
>>What do you mean by saying "moves forward"? lseek? IIRC, lseek in child
>>process doesn't affect the parent process.
>
> It does (on file descriptors resulting from the same open, including
> those created with dup, fork, inherited across exec, etc.
>
> Casper
Thanks for your correction!
--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.