Interrupting very long output in tmux

killterminaltmux

In a (gnome) terminal, if I cat a file which turns out to be much too long, I can always press Ctrlc to interrupt.

However, in tmux, when the same happens, it takes long for the signal produced by the Ctrlc keypress to reach the server, and until that happens, the server is busy with this output, and I'm unable to do anything but watching the flood (or using a different terminal).

This is somewhat similar to the problem described here.

I do not wish to restart the terminal, the server, or even the specific tmux window/pane; using less is a smart habit, but I'm asking here about how to solve problems that already occured, not how to be smart and avoiding them by thinking before acting… there will always be surprises!

So, is there a way to let the terminal stop the floods, discard the sent data, etc.? Anything I can do to release myself from these annoying minutes of watching characters on my screen?

Best Answer

Two proposal

  1. Seldom in case like this CTRL+z is more effective than CTRL+c: it answers faster. After that you suspend the command you can kill it with kill %1 or whatever is the job number. In the hope that you are still able to read anything from the screen (a flooding random binary text can easily mess up your characters set).

  2. In another terminal you can ask pgrep cat (if cat was the command invoked) and identify the cat process is using your cpu or by pstree:

    pgrep cat | awk '{print "pstree -sp "$1}' | sh | grep tmux

    answer with an output like
    init(1)---lightdm(1428)---lightdm(2518)---init(2534)---tmux(22425)---bash(22426)---cat(22532)

    In this case, after you have only to kill the cat PID:
    kill 22532

Note:

  • If you press CTRL+C or CTRL+z and after you minimize the window, probably the system will be faster than you to read the interrupt request. So suspend/break, minimize, wait a little, maximize again, can be a solution too.
  • As you said less is safer.
  • Tested again with tmux 1.8 and working
Related Question