On Fri, Feb 24, 2012 at 11:04 AM, Kristof Provost <kristof@xxxxxxxxxx> wrote: > On 2012-02-24 09:07:40 (+0200), Kosta Zertsekel <zertsekel@xxxxxxxxx> 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. I meant that I don't see any semaphore related stuff in do_exit(). It seems that semaphore just remains there in the system after a user land task is killed... --- KostaZ _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies