I have a process that opens several tcp connections to several browsers on separate ports.
Using netsat the output is something like this :
tcp 0 0 server1.something:myprog client1.something:49987 ESTABLISHED
tcp 0 0 server1.something:myprog client1.something:65987 ESTABLISHED
tcp 0 0 server1.something:myprog client1.something:89987 ESTABLISHED
Now i would like to kill exactly one of the connections? How do i do it? (Since killing the process will kill all connections)
You can't kill a single connection of a process. But you could block it with iptables. So the connection can't provide or receive data and the client will run in a timeout. Save this answer.
For processes listening on a TCP or UDP port, the fuser command along with the -k (kill) option will terminate the related processes for you. Just specify the port type (TCP or UDP) and the port number in your command. For example, this would terminate processes utilizing TCP port 80.
Here are some options:
There doesn't seem to be a well supported way to do this. It is likely that processes will crash if their FDs are unexpectedly closed anyway.
On linux kernel >= 4.9 you can use the ss
command from iproute2 with key -K
ss -K dst client1.something dport = 49987
the kernel have to be compiled with CONFIG_INET_DIAG_DESTROY
option enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With