how to kill a port's external process?

Luke Gorrie luke@REDACTED
Thu Aug 9 23:23:27 CEST 2001

Luke Gorrie <luke@REDACTED> writes:

> I think a really nice and manly way to kill external ports would be to
> hack the "spawn driver" so that Erlang could make a driver ioctl to
> send a signal to a spawned program.

I couldn't resist and hacked in support for doing kill(2) on port
programs. I don't know if the approach is unwise for some reason but
it seems to work nicely.

The interface is a "spawn_drv" module in the kernel application with
these functions:

%% close_output(Port) -> ok | {error, Reason}
%% Close the pipe from Erlang to the port's stdin

%% send_signal(Port, Signal) -> ok | {error, Reason}
%% Signal = hup | kill | term
%% Send a Unix signal to the port with kill(2)

I was lazy and just defined 3 signals, but it's easy to add more.


  1> P = erlang:open_port({spawn, "/bin/cat"}, [exit_status]).
  2> flush().
  3> spawn_drv:send_signal(P, kill).
  4> flush().
  Shell got {#Port<0.7>,{exit_status,137}}

Patch against R7B-3 attached, I hope I built it properly.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: spawndrv.patch
Type: text/x-patch
Size: 5842 bytes
Desc: not available
URL: <>

More information about the erlang-questions mailing list