[erlang-questions] Two questions about open files and file descriptors

73 views
Skip to first unread message

Daniel Dormont

unread,
May 1, 2012, 12:39:12 PM5/1/12
to erlang-questions
Hello Erlangers,

I'm trying to chase down some 'emfile' errors that showed up in my application. I have two questions about this:

1) Is there a way I can see, in a live system, supposing I have a console open, the list of open files and/or file descriptors?

2) Suppose I have code running in a particular process that calls file:open/2, writes some stuff using io:format/3, and then closes the file using file:close/1. During this time, the descriptor returned by file:open is kept only in local variables. Now, in the middle of computing "some stuff", the process crashes. What happens to my open file?

-Dan 

Max Lapshin

unread,
May 1, 2012, 12:46:26 PM5/1/12
to Daniel Dormont, erlang-questions
lsof -p
ulimit

[{Pid, Ports} || {Pid,Ports} <- [{Pid, [L || L <-
element(2,process_info(Pid, links)), is_port(L)]} || Pid <-
processes()], length(Ports) > 0]
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Daniel Dormont

unread,
May 1, 2012, 1:40:12 PM5/1/12
to Max Lapshin, erlang-questions
Thanks. Will that include ports open from processes that have died? That's the specific case I'm trying to understand - what happens if a process crashes with a file open, and how do I recover from it?

-Dan

Lukas Larsson

unread,
May 1, 2012, 2:15:42 PM5/1/12
to Daniel Dormont, erlang-questions
When the process controlling a port dies the port will get what is
equivalent to an exit signal and be stopped. For the specific case of
the file driver, the driver will try to flush all written data before
shutting down the driver, but eventually it should end with a closed
filedescriptor.

Note that if you are not opening the file with raw as arguments, it
will be the file server which is the controlling process.

Lukas
Reply all
Reply to author
Forward
0 new messages