Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I used to do this in the Windows world with tool called TCPView: just select a established connection (ESTABLISHED), then select "Close Connection". I can't find a way to this on Mac OSX or Linux (I need both). The only way I know of is to kill the process that has the port open.

My main use case is to simulate interruptions in connectivity to test failover, like unplugging a cable or losing a router or middleware situations.

share|improve this question
    
Killing the process is not good enough? –  terdon Feb 26 '13 at 14:28

2 Answers 2

up vote 1 down vote accepted

You could attach to your process using gdb and close() the file descriptor corresponding to the connection. You can find out the file descriptor number using lsof -a -i4 -p $PID.

share|improve this answer
    
works! too bad gdb pauses the program, but I'll look more into that –  Rodrigo Gonzalez Feb 26 '13 at 19:52
  • tcpkill -i eth0 { expression }
    (basic command/options)

  • tcpkill -i eth0 port 21
    (Kill all outgoing ftp (port 21) connection)

  • tcpkill host 192.168.1.2
    or
    tcpkill host hostname.domainname.com
    (Kill all all packets arriving at or departing from host 192.168.1.2)

  • tcpkill ip host 192.168.1.2 and not 192.168.1.111
    (To kill all IP packets between 192.168.1.2 and any host except 192.168.1.111)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.