当打开进程终止时,文件将自动关闭 [英] Will the file get automatically closed, when opening process terminates

查看:139
本文介绍了当打开进程终止时,文件将自动关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个进程,它使用file:open打开文件。这个文件会自动关闭,当我的进程将终止?

解决方案

是的。从 file:open / 2 的文档:


返回:

  {ok,IoDevice} 

该文件已在请求的模式下打开。

$ d

/ p>


IoDevice 真的是处理文件的进程的pid。此过程与最初打开文件的进程相关联。如果连接了 IoDevice 的任何进程终止,文件将被关闭,进程本身将被终止。



I have a process, which opens the file by using file:open. Will this file get automatically closed, when my process will terminate?

解决方案

Yes. From the documentation of file:open/2:

Returns:

{ok, IoDevice}

The file has been opened in the requested mode. IoDevice is a reference to the file.

[...]

IoDevice is 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 the IoDevice is linked terminates, the file will be closed and the process itself will be terminated.

这篇关于当打开进程终止时,文件将自动关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆