Re: Semaphore

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Regards,
Kristof


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux