porcelain and external processes

214 views
Skip to first unread message

Rajmohan Banavi

unread,
Oct 26, 2015, 2:26:10 PM10/26/15
to elixir-lang-talk
I am using porcelain to start external processes and observing that the external processes do not get killed when I call stop on the Porcelain returned struct, though it returns ok. For eg

def init do
  p = Porcelain.spawn("/some/external/process", [], [])
end

def shutdown do
  Proc.stop(p) # this doesnt kill/stop the external process :(
end

[1] Even after calling stop, I see that linux "ps" lists the process. What is the right way to stop a process?

[2] I see the elixir process does not get notified if I manually kill the externally launched process (say using kill from cmd line). How can this be achieved so that it can be restarted?


Alexei Sholik

unread,
Oct 26, 2015, 2:59:29 PM10/26/15
to elixir-l...@googlegroups.com
Porcelain simply closes the underlying Erlang port when stop() is called. That works fine with cooperating OS processes but it, unfortunately, cannot terminate OS processes that are supposed to run continuously or that went rogue.

For example, if you spawn `cat` with `in: receive`, calling stop() on it will work fine because `cat` terminates as soon as it sees its input pipe get closed. However, if you spawn `iex`, simply calling stop() won't terminate it.

If you're using the goon driver, you could try Porcelain.Process.signal to send a TERM or KILL signal to the process. With the basic driver nothing can be done to terminate rogue OS processes, short of getting the OS pid and spawning the `kill` utility to get rid of it.

Regarding your second footnote, that's an edge case that I haven't specifically implemented in Porcelain. Are you using the basic driver? I believe you should see some activity when using Porcelain with goon.

Please have a look at this issue https://github.com/alco/porcelain/issues/13 and see if you can contribute your example to the discussion. I'll try to carve some time to come up with a more robust way to deal with non-cooperating OS processes.

Best,
Alex

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/CAJWm%2BfGuuAyX8LuCqqRVYoFtt%3DsF8F9t2mUsX4CKwz%2BpR%2BA3AQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Rajmohan Banavi

unread,
Oct 27, 2015, 2:50:51 AM10/27/15
to elixir-lang-talk
Thanks Alex for the quick response, will add to the github issue.

Cheers.

Reply all
Reply to author
Forward
0 new messages