Since it sounds like you're on Linux or other POSIX system---
You're cat command is waiting patiently for input from its standard input, which in this case is the terminal.
If you type Cntrl-D, an End-Of-File condition will be sent to the cat command, and it will finish.
Answer from antlersoft on Stack OverflowVideos
You can run ctl-z to background it and then kill the PID.
$ ctl z (to background it)
$ kill -9 {pid} 'of process that just got backgrounded'
Often the data has already been sent to the display, and the "long time" is the terminal trying to display the data. Doing anything to the task won't help (i.e., Ctrl+Z or Ctrl+C), you'll need either a faster terminal or something to buffer the data.
I pipe large outputs through less and tail depending on whether I want to view the top or the bottom of the file, since both allow me to easily control the amount of data being sent to the terminal and close the program if it's not what I want.
If the file(s) in question contain lots of data, sending the signal can actually get to cat before it finishes. What you really observe is the finite speed of your terminal - cat sends the data to the terminal and it takes some time for the terminal to display all of it.
Remember that it usually has to redraw the whole output window for each line of output (i.e. move the contents of the window one line up and print the next line at the bottom). While there are techniques and algorithms to make this faster than if it was done the straightforward way, it still takes some time.
Thus, if you want to get rid of the output as quickly as possible, hide the terminal window, because then (usually) no actual redrawing takes place. In a graphical environment this can mean either minimizing the window or switching to a different virtual desktop, on the Linux virtual console just switch to another one ((Ctrl +)Alt + Fx).
Also notice that if you ran this over a slow network link (SSH over a GSM connection, for example), you would definitely see much less output before cat is killed by the signal, because the speed of the terminal redrawing wouldn't be the bottleneck any more.
Terminal Setup
I reckon this is more to do with the way the terminal is set up, than with any buffering issue. Check the output of stty -a | grep intr, you should have intr = ^C; on the output line if Ctrl-C is enabled at the tty/pty. If it isn't, you can use stty intr ^C to enable it. Add the line to your .tcshrc or .login to make it permanent (or delete the line that changes it in the first place!).
Failing Ctrl-C, you can also try sending SIGQUIT with Ctrl-\. If this doesn't work, again check stty -a | grep quit to see if it is properly set up.
Terminal Emulator Setup
Also check the settings for your terminal emulator (if you are using one), it may be that there is a shortcut set up at this level (maybe for copy or something) and the Ctrl-C does not reach the pty level. A shortcut could also be set up somewhere else in your desktop environment or Window system.
A good test on Linux if you are using a terminal emulator is to switch to a Linux console (Ctrl-Alt-F1), login there and see if the same behaviour occurs. If it doesn't then this suggests the problem lies with your Window system or terminal emulator.
It could be an issue with the delay between data being read from the pty device as suggested by peterph. But if this is the case and you do actually have to wait minutes for the data to be displayed, then surely the terminal emulator is buffering way too much data (or your PC is very slow). The answer would be to find a way to reduce that buffer size in your terminal emulator settings or use a different one.
Extra Tip
Something else worth adding; I usually end up in the runaway cat situation when if I accidentally cat a binary file. The other effect of this can be to screw up your terminal settings (if the binary data happens to match various terminal escape codes which it often does). If tput is installed (usually is by default), you can avoid having to restart with the following command:
tput reset
I've done a little bit of searching, but I'm having trouble using adequate search terms for this one, since I don't know exactly what to call what's happening.
Every once in a while I will cat a file that can't be shown as text properly, and the cl bugs out trying to display it. For example an image file. So far the only way I've found to stop it is to close the shell. control + c, q, quit, haven't worked. I'm learning through denial and error so that's all I can think of to try.
So two questions: what is it called when this happens? And how can I avoid/stop it?
Thanks!
EDIT: Here are some screen shots
Before entering command
Lost control of shell
Continues until exiting shell..
Also makes the 'beep' sound continually (probably not the right terminology there)
So far I've tried:
Control + C Control + Z quit exit clear reset
Nothing seems to work since I can't enter commands
Solution:
Use 'less' instead of 'cat', since cat is the wrong tool for the job.