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!
$\begingroup$ I believe @Rojo made something to autosave the notebook automatically before each run some time ago $\endgroup$– Dr. belisariusFeb 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$– DumpsterDoofusFeb 14, 2015 at 21:14
$\begingroup$ @DumpsterDoofus: Same here, have never had a problem with losing NB... $\endgroup$– ciaoFeb 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 E2Feb 14, 2015 at 23:16
$\begingroup$ Related: mathematica.stackexchange.com/q/13997 and mathematica.stackexchange.com/a/8762/5 $\endgroup$– Michael E2Feb 14, 2015 at 23:18
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
Presto, kernels killed!
On OSX, if you don't have the pidof command do
brew install pidof.
$\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$– abcdMay 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$– AcusJun 13, 2022 at 10:41