Closed oubiwann closed 3 years ago
Take a look at these examples ... maybe something useful (from https://github.com/saleyn/erlexec/blob/master/src/exec.erl):
stop_and_wait(Pid, Timeout) when is_pid(Pid) ->
gen_server:call(?MODULE, {port, {stop, Pid}}, Timeout),
receive
{'DOWN', _Ref, process, Pid, ExitStatus} -> ExitStatus
after Timeout -> {error, timeout}
end;
terminate(_Reason, State) ->
try
erlang:port_command(State#state.port, term_to_binary({0, {shutdown}})),
case wait_port_exit(State#state.port) of
0 -> ok;
S -> error_logger:warning_msg("~w - exec process terminated (status: ~w)\n",
[self(), S])
end
catch _:_ ->
ok
end.
wait_port_exit(Port) ->
receive
{Port,{exit_status,Status}} ->
Status;
_ ->
wait_port_exit(Port)
end.
notify_and_exit(true, Pid, OsPid, Reason) ->
Pid ! {'DOWN', OsPid, process, self(), Reason},
exit(Reason);
Also see How do you kill an OS process that was opened with open_port on a brutal_kill?. Highlight:
More from that thread.
Maybe just use https://github.com/saleyn/erlexec? Has all the features we need ...
Good docs: http://saleyn.github.io/erlexec/
Yeah, switching to erlexec
fixed it!
Right now, it seems that only calling
(exit)
from the REPL does go through the proper termination sequence (but onlysendmidi
is killed;receivemidi
remains running). Issuing a SIGINT or SIGTERM don't seem to executing the full termination sequence at all, when run via rebar3 and the LFE REPL. Both OS processes forsendmidi
andreceivemidi
remain running.Tasks:
DOWN
message?sendmidi
) while the other isn't (receivemidi
)Related to #89
Part of epic #80