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

Éric Pailleau <>
Fri Oct 16 19:18:36 CEST 2015


Hi, 
Your port just have to check getppid and exit if PPID is 1. The case if a parent exit, the child inherits of parent 1 (init).
This can be as well with time interrupt if this cannot be done in a loop.
Regards 

Le 16 oct. 2015 11:30, Nicolas Martyanoff <> a écrit :
>
> 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 
>  
> _______________________________________________ 
> erlang-questions mailing list 
>  
> http://erlang.org/mailman/listinfo/erlang-questions 


More information about the erlang-questions mailing list