Getting zombies with erlexec

Hi! I’m still getting zombie processes with erlexec and nothing that I do seems to be able to resolve this. Firstly, i’m on linux. Secondly, i can’t use muontrap, since I need to stream input and output into the other process.

Here’s the code:

  #... Genserver Headers
  def init(_) do
    :erlexec.run_link("priv/forever.sh", [:stderr, :stdout, :kill_group])
    #...

forever.sh

#!/bin/bash

while true; do
  sleep 1
end

Control-c/a definitely creates a zombie (I think the GenServer doesn’t even get the stop message), and even System.stop(0) creates a zombie.

I’m free to put anything in the top of the forever script, so if I can use that to, maybe set the process group or a job, I can definitely do that, but I’m not familiar enough with linux to know if that makes sense. thanks

Thanks in advance.

2 Likes

Not sure if rambo could help there as I think it does the same thing as muontrap, but maybe worth checking.

1 Like

You can also take look at ex_cmd.

1 Like

There is no clean way to do it without using middleware if you are consuming stdin. You need another OS process which act like monitor and do the cleanup. mountrap & ExCmd are such middlewere, but mountrap does not support communicating with the external process and ex_cmd does.

Also If you are streaming a lot of data in/out of beam then it can lead to memory issue. ex_cmd also solves that. See memory issue mentioned here

2 Likes

sadly none of the above solutions worked. I was able to get a solution I was okay with:

  1. use :os.getpid() to get the os pid of the erlang process.
  2. in the shell script, patrol to see if erlang process is still alive
  3. if it’s not, tear down the script and all its children.