[erlang-questions] Sending signals to non-erlang processes

Nicolas Martyanoff khaelin@REDACTED
Fri Oct 16 11:30:06 CEST 2015


Hi,

I am writing an OTP application which spawn instances of a non-erlang daemon
to run tests. I use a port to execute the daemon and read its output.

However if for some reason my erlang application exits, the spawned daemon
will not be killed. The documentation indicates:

    If the port owner terminates, so does the port (and the external program, if
    it is written correctly).

The daemon itself behaves like most UNIX daemons and terminates on SIGTERM or
SIGINT. But exiting the erlang VM (using ^C + abort) does not seem to do
anything.

Is that on purpose ?

I also cannot find a way to actually stop the spawned application,
port_close() does do it. The "UNIX way" is to send SIGTERM, wait for a bit,
then send SIGKILL if the application did not stop. But I cannot find an erlang
function to send a signal to an external process. I made a temporary fix using
os:cmd("kill ..."), but it feels like a hack.

Is there a reason not to have something such as os:kill(Signo, Pid) ?
Would erlang developers accept a patch to add it ?
It could be a first step toward support for proper termination via
port_control(), and an open_port() option to automatically close the child
process when the port is closed.

Regards,

-- 
Nicolas Martyanoff
khaelin@REDACTED



More information about the erlang-questions mailing list