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 th开发者_JAVA技巧e client & server are in the middle of some exchange. Is this doable though a shell command ?
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.
No, not on standard linux, there is no such facility.
精彩评论