[erlang-questions] Erlang VM crashed due to io output?

Michael McDaniel erlangx@REDACTED
Thu Jul 19 21:12:00 CEST 2007


On Thu, Jul 19, 2007 at 01:32:58PM +0200, Daniel Luna wrote:
> On Thu, 19 Jul 2007, Ludovic Coquelle wrote:
> > Sorry for posting again this question, but I think there is something
> > important to know and I can't figure out what.
> >
> > I run a command printing simple text on default io device (stdout):
> > bash> erl -noshell -eval "lists:foreach(fun(N) -> io:format(\"~w~n\", [N])
> > end, lists:seq(1,5)), erlang:halt()."
> > 1
> > 2
> > 3
> > 4
> > 5
> >
> > That's the behaviour I expected.
> > But if I try to pipe the result, erlang crash:
> > bash> erl -noshell -eval "lists:foreach(fun(N) -> io:format(\"~w~n\", [N])
> > end, lists:seq(1,5)), erlang:halt()." | head -n 3
> > 1
> > 2
> > 3
> > Crash dump was written to: erl_crash.dump
> > init terminating in do_boot ()
> >
> > What's happening?
> > Is it a normal behaviour?
> 
> I was hoping someone else would answer, and thus didn't reply to your 
> first message.
> 
> I'm not suprised at all, but my answer should still be taken with a grain 
> of salt.
> 
> My guess is that 'head -n 3' will take the first three lines of output and 
> then kill the pipe. Erlang will be very upset about someone killing its 
> standard out, and thus crash (and of course the error message is written 
> to stderr and thus not caught by head).
> 
> If it's ok that erlang crashes, you could pipe also stderr, otherwise I 
> recommend that you do the head thingie inside erlang.
> 
> HTH
> 
> /Luna
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

 And, in fact, using 'head -n 7' succeeds, adding support for your analysis.
 My Ubuntu system,
 Linux delora 2.6.20-15-386 #2 Sun Apr 15 07:34:00 UTC 2007 i686 GNU/Linux
 using R11B-5, exhibits same crashing behaviour using 'head -n 3'.

~Michael



More information about the erlang-questions mailing list