For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2006 > exit() and open files









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author exit() and open files
Spoon

2006-08-14, 4:01 am

Hello group,

My man page for exit() states:

All open streams are flushed and closed.

OK, so the C library is supposed to take care of open streams.

What happens to files that were opened with open() ?

I don't expect the C library to take care of them. Do they remain
open? I suppose that, once my program disappears, the OS decrements
some reference count, and decides that nobody has that specific file
open anymore?

The reason behind these questions:

I have a PCI board in my system. When I open the associated device node
and use it, then fail to close it, my entire system often hangs.

Is it reasonable for a driver to be so cranky?
Shouldn't the OS "inform" the driver when the last process to have the
device open disappears, so that the driver can perform any clean-up?

Regards.
Rainer Temme

2006-08-14, 4:01 am

Spoon wrote:
> My man page for exit() states:
> OK, so the C library is supposed to take care of open streams.
>
> What happens to files that were opened with open() ?
>
> I don't expect the C library to take care of them. Do they remain
> open? I suppose that, once my program disappears, the OS decrements
> some reference count, and decides that nobody has that specific file
> open anymore?
>
> The reason behind these questions:
>
> I have a PCI board in my system. When I open the associated device node
> and use it, then fail to close it, my entire system often hangs.
>
> Is it reasonable for a driver to be so cranky?
> Shouldn't the OS "inform" the driver when the last process to have the
> device open disappears, so that the driver can perform any clean-up?


Spoon,

Open files (from open(), socket(), pipe() etc) are closed automatically,
when a process exits. This is not actively done by exit(), its done by
the OS.

So, to the first question ... they don't remain open.

To your second question ... This sounds pretty much like a bug in
the devicedrivers cleanup-code.

Rainer
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com