[erlang-questions] erlang port and C executable

Edwin Fine erlang-questions_efine@REDACTED
Sun Nov 23 20:10:54 CET 2008


On Sun, Nov 23, 2008 at 11:57 AM, Per Hedeland <per@REDACTED> wrote:

> "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."


You're probably right. But nothing wrong in the C program, I don't think.
That's why I found it a bit frustrating to get the Erlang program working
correctly.


>
>
> > 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.
>

There are well-known techniques to starting daemons that don't rely on open
ports (e.g. fork a child, close all open files, fork another child, trap
signals, open stdin/out etc). So I am not sure this such is a good feature
because it makes it difficult to kill misbehaving OS programs that were
spawned by Erlang.


> >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.
>

I understand - I was pointing more to the idea than the implementation. I
think Erlang/OTP should perhaps provide a standard wrapper C program that
will run any program as a child, and has a back-channel that allows you to
kill it (and its child) if the child becomes non-responsive.


> --Per Hedeland
>
> Edwin Fine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081123/0920021b/attachment.htm>


More information about the erlang-questions mailing list