how to kill a port's external process?

Luke Gorrie <>
Thu Aug 9 20:35:21 CEST 2001


Garry Hodgson <> writes:

> > This goes beyond Erlang, but... killing a process based on the name
> > of a program is always dodgy at best, given that a program can change
> > what it shows up as in 'ps'. 
> 
> in this case, the external program does not.  i've gotten it working
> using this hack, and it works just fine for my purposes.  i expect i'll
> let it be.

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 think that's actually pretty straight forward - with some help I've
added an ioctl function to the spawn driver which I use to close
Erlang's sending pipe to a spawned program without closing the reading
one. I've attached a patch which should be mostly reusable.

The file to hack is erts/emulator/sys/unix/sys.c

If you hack that then you can then use erlang:port_command/2 to send a
message to the driver (erlang sends an I/O list, driver gets it as a
char*) and it can arbitrarily interpret that, e.g as:

  <<?SIG_REQUEST:8/integer, Signal:32/integer>>

I for one would cheer if someone were to do this :-) with just a few
spawn driver ioctls we could make a unix command shell in erlang.
Then you could annoy both bash and tcsh people when they use your
computer ;-)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sys.patch
Type: text/x-patch
Size: 2693 bytes
Desc: spawn driver ioctl patch
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20010809/1fca7d33/attachment.bin>


More information about the erlang-questions mailing list