问题
I have a process, which opens the file by using file:open. Will this file get automatically closed, when my process will terminate?
回答1:
Yes. From the documentation of file:open/2:
Returns:
{ok, IoDevice}The file has been opened in the requested mode.
IoDeviceis a reference to the file.
[...]
IoDeviceis really the pid of the process which handles the file. This process is linked to the process which originally opened the file. If any process to which theIoDeviceis linked terminates, the file will be closed and the process itself will be terminated.
来源:https://stackoverflow.com/questions/28066839/will-the-file-get-automatically-closed-when-opening-process-terminates