I'm trying to save the contents of an Emacs scratch buffer, which I can't access any more due to an inaccessible terminal.
On my Linux box I've ssh'ed to a server, and started Emacs. My Linux box has now frozen, however I can still see the Emacs process alive on the server ssh'ed into.
Is there a way to get Emacs to dump/save the contents of its scratch without having direct access? I had two thoughts:
- Send a signal to the process so that Emacs dumps its core, and then reload the core (and then save scratch)
- Send keystrokes to the stdin of the process which would instruct the Emacs process to save the file, ie: via
echo "abd" > /proc/<pid>/fd/0
.
I tried this by opening two terminals, and the keystrokes appear on the target terminal, however they aren't captured by Emacs.
Best Answer
I've had some luck with attaching gdb to the running process. Borrowing heavily from: How to attach terminal to detached process?
write-file
mkfifo /tmp/some_name
gdb -p [pid]
call close(0)
call open('/tmp/some_name', 0600)
. At this point gdb will appear to hangecho '(write-file "savedresults")' > /tmp/some_name
ctrl-d
The contents of scratch are written out to the file 'savedresults'. Interestingly
(write-file "savedresults")
is appended to the file (unsure why).C-x C-w name
mkfifo /tmp/some_name
gdb -p [pid]
call close(0)
call open('/tmp/some_name', 0600)
. At this point gdb will appear to hangcmd="^X^Wsavedresults"
(input ^X via key sequence: CTRL-V CTRL-X, similar for ^W"echo "$cmd" > /tmp/some_name
ctrl-d
Contents are written to file 'savedresults'.