Quoting from an answer to Typesetting the entire Song That Never Ends
I ran this code once, and aborted the process after it reported producing something like 47,000 pages (in a very short amount of time). Unfortunately, my computer complained that the resulting pdf file was "damaged" and could not be opened. A better (perhaps impossible?) answer would produce a file such that the output could actually be viewed once the process was killed (or died).
This got me curious (and it is merely a curiosity). Can TeX die gracefully? Since its output is a PDF, presumably it needs to do some non-trivial stuff at the end to ensure that the PDF is valid so merely killing TeX is too abrupt.
A more graceful method would be for TeX to ask at each shipout "Shall I continue?", but that suffers from the other extreme: it is too intrusive as the user needs to keep giving commands to keep TeX going.
Off the top of my head, the only way I can think of to communicate with a running process in a non-blocking way is via a file. At each shipout (or other), TeX can check for the existence of a file and continue if it doesn't exist, and if it does then read the file and carry out whatever actions said file contains (thus allowing for more refined communication).
Is there a better way?

{to-TeX-or-not-to-TeX}.;)– Count Zero Jan 30 '13 at 11:01ctrl-cand thenxthen alsopdftexwill produce a valid PDF. – Stephan Lehmke Jan 30 '13 at 16:37Andrewuses but when stopping a nonstopmode run withC-cC-kfrom within emacs, the dvi/pdf is corrupted and can not be opened via xdvi or a pdf viewer. However running from the command line,ctrl-cand thenXdoes the trick as you said. – Jan 31 '13 at 10:29kill. But in this case no amount of interaction will save you. When you abort by hittingX, you'll see the "postamble" in the console, loading fonts and such. So TeX is definitely finishing gracefully. – Stephan Lehmke Feb 01 '13 at 07:37