Semaphore
Kristof Provost
kristof at sigsegv.be
Fri Feb 24 04:04:37 EST 2012
On 2012-02-24 09:07:40 (+0200), Kosta Zertsekel <zertsekel at gmail.com> wrote:
> >> > Imagine a driver which only one app can use at a time (perhaps a serial
> >> > port). The kernel will take a lock when the user space app open()s the
> >> > device node and release it when it close()s.
> >> > If the app segfaults in between the open() and close() the lock will
> >> > still get released. The kernel always cleans up open files for stopped
> >> > processes, regardless of how they stop. During this cleanup the kernel
> >> > will close() the device node, and as a result the driver will release
> >> > the lock.
>
> Can you please point to some code in Linux Kernel that does the job?
In kernel/exit.c, look at do_exit(). It cleans up a process after it's
terminated (for whatever reason).
It does a lot of cleanup, but through exit_files() -> put_files_struct()
-> close_files() it ends up iterating over all open file descriptors and
closing them.
What's done for each close depends on what the process had open. Normal
files will just be closed, or a TCP socket might be closed, or if a
device node was opened the corresponding drivers close() function will
be called.
Regards,
Kristof
More information about the Kernelnewbies
mailing list