Saved for when Future Steve goes searching for examples on how to do this again.

I had a project that required acting as a server by opening a socket on a particular port and then listen for incoming connections. Not that particularly interesting. However, the process of building it was kind of a pain because the program would periodically linger in the background holding the socket open and launching a new instance would fail because hey look someone already has that socket open.

In order to optimize my laziness and reduce my overall frustration I opted to have the new instance find and kill the old instance. It's a dev server, what do I care? Anyway.

There are tools that show you which processes own which ports. There are tools that kill processes. There aren't really tools that show you port owners and then let you kill them. Certainly not in any easy to use way. On top of that, all the examples online just show you how to marry the two, usually by grepping your way through a whole bunch of string dumps, and well, nah.

Just query the damn socket table: