DEvil0000

DEvil0000

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

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 = Port.open({:spawn, "sleep 360"}, [:exit_status])
        Process.link 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…

Most Liked

grych

grych

Creator of Drab

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

OvermindDL1

OvermindDL1

It’s not possible to know it segfaulted, and a return code from an application may not actually be an error but could be returning valid information that is actually wanted (this is done quite commonly), only the user can know.

grych

grych

Creator of Drab

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

This is an exit of the erlang process, not the unix one. Port.open 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.

Last Post!

DEvil0000

DEvil0000

I was expecting those cases would also get reflected in the exit beeing not normal so link would make sense.

grych

    March 12

Everything works as expected.

DEvil0000:
{port<0.6363>, {:exit_status, 137}}

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

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement