[erlang-questions] erlang port and C executable

Per Hedeland per@REDACTED
Sun Nov 23 17:57:43 CET 2008


"Edwin Fine" <erlang-questions_efine@REDACTED> wrote:
>
> One of the most annoying aspects is that under
>circumstances that are not clear to me, the C program that is spawned
>sometimes does not seem to be sent a signal for end of file when you close
>the port, so if it is reading stdin, it's just going to sit there until
>killed manually.

This should never happen - i.e. there is no "signal" for end of file,
it's just the result of reading when there is nothing more to read - but
a port program that actually reads its stdin should always get end of
file when the port is closed (after having read what there is to read,
if anything). "You're probably doing something wrong."

> Worse, if it gets stuck doing something and is NOT reading
>stdin then you are out of luck.

This is expected, and can be considered a feature - it allows you to
e.g. start a daemon that *should* keep running after you close the port.

>But what if the 'C' program is not under your control, say, it's part of
>Linux, and you need to make sure it's killed when you are done? Then I
>believe you need to write a wrapper around the 'C' program. I refer you to
>the following post for an interesting way to do this:
>
>http://www.erlang.org/pipermail/erlang-questions/2007-October/030377.html

It may be "interesting":-), but I wouldn't really recommend that you use
that "code", it was kind of a "I bet it can be done" thing, in
particular implementing {packet, 2} protocol in 'awk' is not exactly
ideal.:-) 2-3 lines of readable C code would be a better idea.

--Per Hedeland



More information about the erlang-questions mailing list