Hey, I’m trying to run binary with server in background and I don’t know how to stop it.
My code:
args = []
name = "example_server"
# check if example_server is in PATH environment variable
if System.find_executable(name) do
pid = spawn(fn -> System.cmd(name, args) end) # initialize: start server
# real work here ...
Process.exit(pid, :normal) # clean-up: here I'm trying to stop server
else
throw "oops :-)"
end
I through that &System.cmd/2
will be stopped if parent (spawned) process exits, but it’s not working.
Can you help me with it?