`open_port` and zombie processes

Elixir has a disclaimer about ports and zombie OS processes, Port — Elixir v1.15.7, basically unless the spawned external program checks if its stdio is closed, it’s not automatically terminated. I’m sure there are situations where this is desirable but there’s a ton of programs out there that cannot be easily (i.e. without things like wrapper shell scripts) interacted with using ports because of this problem.

I wonder if being able to opt-in to such automatic termination was ever discussed?

Something like this perhaps?

- P = open_port({spawn, "python3 -m http.server"}, []).
+ P = open_port({spawn, "python3 -m http.server"}, [kill]).

@wojtekmach just use the battle tested erlexec. You’ll be able to control stdin/stdout and many other things. No more zombies…

Hey @wojtekmach, is this just around in case the VM crashes (and specifically crashes in a way where there is a moment for recourse)?

I think we have talked about it before, but it was a long time ago and I can’t recall if there was a technical reason not to do it, or just lack of priority/time.

That being said, I think now that we have erl_child_setup on Unix, we could employ a similar method as erlexec to make sure port programs terminate properly. On Windows it seems like you can join processes into the same job and then they will all be terminated when the emulator terminates.