Oddbean new post about | logout
 Linux - have a subprocess stuck on a network connection, want to kill that connection to force it to create a new one? "ss" (part of iproute2 package) can do that for you. Using rclone as the example, pretend it's been launched by the backup tool (restic, duplicity, etc.) and stuck talking to a remote host.

Find the process and it's stalled TCP connection:

    ps axo pid,comm | grep [r]clone
    # 6874 rclone

    ss -ntp | grep [r]clone | awk '{print $5, $6}'
    # 74.120.9.121:443 users:(("rclone",pid=6874,fd=9))

Pause the process, kill the connection (as root), resume the process:

    kill -STOP 6874
    sudo ss -K dst 74.120.8.14 dport 443
    kill -CONT 6874

Requires a modern kernel (>=4.9) with CONFIG_INET_DIAG_DESTROY compiled into the kernel.

#linux #networking #opensource