Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are files descriptors closed when process terminates in Linux?

There is a process in Linux (Ubuntu) that opens a file for reading but does not close it deliberately. Is the file descriptor closed by the OS automatically when the process is terminated?

My specific case is in Rails application, where I open a binary file. My web server spawns multiple Rails processes. The file is opened from a singleton in each Rails process. I need to know if this binary file is closed automatically when the Rails process is terminated.

like image 266
Evgenii Avatar asked Oct 11 '25 23:10

Evgenii


1 Answers

Yes, closing all open descriptors is part of the process termination routines. You can see it at the do_exit() function, which calls exit_files() which also, at some point, will call close_files().

like image 132
C2H5OH Avatar answered Oct 14 '25 12:10

C2H5OH