[erlang-questions] Stop C-port in case of erlang process killed
Michael Santos
michael.santos@REDACTED
Mon Nov 2 18:36:56 CET 2015
On Mon, Nov 02, 2015 at 07:59:18PM +0300, Kirill Ratkin wrote:
> Hi,
>
> I'm developing C-based program which should work as port.
> Issue is when erlang process hardly killed (by exit(Pid,kill)) from
> observer for example. In this case C-process doesn't see what happen in
> Erlang node and continues to work. Is there some way to catch such
> situation in C?
In the port, check for EOF when doing the read on stdin and exit. A port
is basically written like a component in a shell pipeline:
1> P = open_port({spawn, "/bin/cat"}, [binary]).
#Port<0.749>
2> erlang:port_info(P).
[{name,"/bin/cat"},
{links,[<0.52.0>]},
{id,11984},
{connected,<0.52.0>},
{input,0},
{output,0},
{os_pid,5465}]
3> erlang:port_command(P, "foobar\n").
true
4> flush().
Shell got {#Port<0.749>,{data,<<"foobar\n">>}}
ok
4> self().
<0.61.0>
% shell process owns the port: killing the Erlang process kills the port
5> a = b.
** exception error: no match of right hand side value b
6> self().
<0.64.0>
7> erlang:port_command(P, "foobar\n").
** exception error: bad argument
in function port_command/2
called as port_command(#Port<0.749>,"foobar\n")
> It seems C-process sees nothing when erlang processe killed. I tried to
> catch signals (SIGPIPE and others).
The port will receive a SIGPIPE if it tries to write to stdout.
> I run C-process under 'strace' and
> tried to gdb it. There are no messages/signals come to C-process excepting
> some read/write periodical messages which looks like heartbeat.
>
> Maybe I need to make some 'monitor' or 'link' of Erlang process from
> C-process ...
>
> BR
> Kirill
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list