linking a port / exit normal in case of kill -X <os_pid>

Tags: #<Tag:0x00007f1142727658> #<Tag:0x00007f1142727518>


Hi there,
I want to open a os process from elixir and get informed in case it crashes. I tried it with port and link but when I kill the external os process the exit always reports normal.
I was expecting to get something else then normal when it exits abnormal like in kill -9 or kill -15.

Since I am actually using elixir 1.5 my test code looks like:

       :erlang.process_flag(:trap_exit, true)
        port ={:spawn, "sleep 360"}, [:exit_status]) port
        :erlang.monitor :port, port

And I get the following:

{#Port<0.6363>, {:exit_status, 137}}
{:EXIT, #Port<0.6363>, :normal}
{:DOWN, #Reference<0.3242658756.1180172289.143115>, :port, #Port<0.6363>, :normal}

The only thing I could use as a workaround is the exit status as it looks like.

Does one of you have a good idea how to get link working for this case?

Is this a bug or a feature?

Communication with os processes, killing them or sending signals is quite tricky anyway in erlang…


Everything works as expected.

When you kill the process in unix, its exit status is set to non-zero value, depending on the signal you’ve sent (128 + signal number, so in your case it is 128+9=137).


I was expecting exit beeing not normal when the process got killed or died unexpectedly so a link would be usefull.
Why is the exit normal in such cases?


I think you are missing the difference between OS and Erlang processes.

This is an exit of the erlang process, not the unix one. creates an erlang process, which runs the external command and waits for it to end. From the erlang point of view, the port process finished normally - it did the job.


I get the difference but why should elixir assume it did the job/its a normal exit if the process was e.g. segfaulting. This does not make much sense to me