This will force kill emacs daemon from bash
. If there is no emacs running and when we run emacsclient -e "(kill-emacs)"
, which starts emacs and kills it again. I just added simple if/else to prevent that.
- Instead of
kill-emacs
you can use brutally-kill-emacs ()
that is defined in @Constantine's answer.
#!/bin/bash
num=$(ps aux | grep -E "[e]macs --daemon" | wc -l)
if [ $num -ge 1 ]; then
emacsclient -e "(brutally-kill-emacs)" > /dev/null 2>&1
# following commands guarantees
kill -9 $(ps aux | grep -E "emacs" | awk '{print $2}')
(killall emacs) > /dev/null 2>&1
(killall emacsclient) > /dev/null 2>&1
kill -9 $(ps aux | grep -E "[e]macs" | awk '{print $2}') > /dev/null 2>&1
else
echo "emacs is already killed."
fi
If you are a m
Sometimes following zombie process remain opened and consumes all the memory so kill -9 $(ps aux | grep -E "emacs" | awk '{print $2}')
will be your friend.
alper 4785 100.0 0.0 4461068 7860 ?? R 1:27AM 41:42.43 /usr/local/Cellar/emacs-head@26/26.3_1/Emacs.app/Contents/MacOS/Emacs -Q -l /Users/alper/.emacs.d/elpa/async-20200809.501/async.elc -batch -f async-batch-invoke
kill-emacs
doesn't work other elisp approaches may also be fouled up, as they probably end up callingkill-emacs
one way or another. What error do you get? It may be easier to fix the error. – Tyler Dec 16 '14 at 20:37kill -9
on the current Emacs pid for instance. You'd have to be very messed up to break that. – PythonNut Dec 16 '14 at 20:38kill-emacs-hook
tonil
before callingkill-emacs
. You can also get Emacs's pid usingemacs-pid
and make it commit suicide by callingcall-process
with "kill -9
". – Constantine Dec 16 '14 at 20:43yas-global-mode
active. For every buffer that's used (even the minibuffer),yas-minor-mode
is turned on and errors out. Note that this means the minibuffer can't be used, but you could still possibly useeval-last-sexp
. – Sean Allred Dec 16 '14 at 21:10pkill
will kill them all (which I don't want) andpgrep
won't tell me which one is the one I want to kill. – PythonNut Dec 16 '14 at 21:10