Manohar
Manohar

Reputation: 3975

close a socket from shell

I am working on a feature that relies on socket communication. One test case I am considering is abrupt socket failures. for ex: I want to close the socket the client has established from the shell, when the client & server are in the middle of some exchange. Is this doable though a shell command ?

Upvotes: 0

Views: 1338

Answers (2)

Ben Voigt
Ben Voigt

Reputation: 283624

Do you want to close it (per your title), or abruptly interrupt it in order to test error-handling code (per your explanation)?

You should be able to interrupt communications on a particular socket using netfilter and appropriate match engines (e.g. pid and port number), and you definitely can run iptables from the shell.

If you want to close the socket, you can just terminate the peer process.

Upvotes: 2

bmargulies
bmargulies

Reputation: 100013

No, not on standard linux, there is no such facility.

Upvotes: 0

Related Questions