killing processes

2020-07-02

 | 

~2 min read

 | 

262 words

UNIX systems come with a utility, kill which, as might be expected, terminates processes.

I wrote about it previously in the context of killing a process that’s occupying a port that I wanted to use [add link].

The thing is - sometimes it doesn’t actually terminate the process.

For example:

% lsof -i :8000
COMMAND  PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    8061 stephen   27u  IPv4 0x5bfc2cdc0d1bfc4b      0t0  TCP localhost:irdmi (LISTEN)
% kill 8061
% lsof -i :8000
COMMAND  PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    8061 stephen   27u  IPv4 0x5bfc2cdc0d1bfc4b      0t0  TCP localhost:irdmi (LISTEN)

Kill didn’t fail. It didn’t exist with a non-zero error code. It just… didn’t terminate the process.

Fortunately, there is an escape hatch, the signal. There are multiple signals that can be sent along with the termination order. The common ones listed in the manual include:

Some of the more commonly used signals:

1       HUP (hang up)
2       INT (interrupt)
3       QUIT (quit)
6       ABRT (abort)
9       KILL (non-catchable, non-ignorable kill)
14      ALRM (alarm clock)
15      TERM (software termination signal)

These can be used in multiple ways. For example - three distinct ways to call with the QUIT command are:

kill -s QUIT 8000
kill -QUIT 8000
kill -3

In my case, I figured the non-catchable, non-ignorable kill would be sufficient for my purposes:

% kill -s KILL 8061
% lsof -i :8000

Turns out I was right!


Related Posts
  • Windows: Killing Services
  • Zsh: Suspended Jobs


  • Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!