6
$\begingroup$

Sometimes the kernel hangs and I'd like to see if I can kill the math-kernel process without destroying my front-end session and losing the changes in my unsaved notebook!

$\endgroup$
6
  • $\begingroup$ I believe @Rojo made something to autosave the notebook automatically before each run some time ago $\endgroup$ Feb 14, 2015 at 20:56
  • 2
    $\begingroup$ Usually I just go into Task Manager on Windows and manually kill the MathKernel objects. I don't think I've experienced failures with this, but maybe others have experienced otherwise? $\endgroup$ Feb 14, 2015 at 21:14
  • $\begingroup$ @DumpsterDoofus: Same here, have never had a problem with losing NB... $\endgroup$
    – ciao
    Feb 14, 2015 at 21:52
  • $\begingroup$ I've experienced many permutations of possibilities. On which versions, whether betas or not, etc., are all confused in my memory. If the front end is not hung, I can (almost always) save while the kernel is running, as well as kill the kernel from the command line without crashing the front end. If the front end is hung, then sometimes the front crashes when the kernel is killed; but this has not yet happened with V10.0.2. In V10.0.2, killing the kernel has been "safe" (knock on wood). $\endgroup$
    – Michael E2
    Feb 14, 2015 at 23:16
  • $\begingroup$ Related: mathematica.stackexchange.com/q/13997 and mathematica.stackexchange.com/a/8762/5 $\endgroup$
    – Michael E2
    Feb 14, 2015 at 23:18

1 Answer 1

4
$\begingroup$

In your aliases file (~/.zsh_aliases) add

alias a=alias
a km='kill -9 `pidof WolframKernel`'

Reload your shell. Now, if the front-end is hanging and you can't quit the kernel but don't want to lose your unsaved notebook changes, simply open a shell and type

km

Presto, kernels killed!

On OSX, if you don't have the pidof command do brew install pidof.

$\endgroup$
2
  • $\begingroup$ This does not work for me. It successfully quits the kernel when the front end is not stuck, but when it hangs it does not stop the OS X rainbow wheel from spinning and have to force-quit, losing all unsaved progress. $\endgroup$
    – abcd
    May 22, 2022 at 13:07
  • 1
    $\begingroup$ I would not start with -9. If you want to abort, for example it is useful to send a signal -2 , first, which tries to open control window an allows to abort/quit kernel gracefully. $\endgroup$
    – Acus
    Jun 13, 2022 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.