'How to shutdown jupyter notebook app (server) without using ctrl-c?

I run a jupyter notebook in the background on a Mac using

>jupyter notebook &

Because it is running in the background I can't use use ctrl-c to kill it. Furthermore no processes seem to have the name jupyter in the activity monitor.

This github issue suggests that this no way to do it from the browser: https://github.com/jupyter/notebook/issues/1530 however it says it should be possible to do from the command line using jupyter notebook stop <portno> but that does not seem to work for me.

How do I shutdown the jupyter server (ideally without having to search for the pid and then invoking kill)?



Solution 1:[1]

Starting from jupyter notebook version 5.1.0, the command

jupyter notebook stop <port number>

should shutdown the notebook server. If you don't enter a port, it defaults to 8888 as that is the default. To know on which ports the servers are currently running, you can do

jupyter notebook list

With jupyter notebook version 5.0, if it is running in the background of your terminal a solution is to do as @juanpa.arrivillaga wrote in the comments:

jobs

to see the jobs running in the background if there is only one and it is the jupyter notebook then

fg

will bring it back to the foreground at which point you can kill it with ctrl-c. And if there are many processes in the background, for example, jobs returns

[1] Running firefox &

[2] Running jupyter notebook &

[3] Running python calc.py &

then fg 2 brings the wanted process back to the foreground to be able to kill it with ctrl-c, or in one step kill %2.

Solution 2:[2]

In a terminal you could run

pkill -f -1 jupyter*

Or I have found this to work when all else fails

sudo pkill -1 -f python

Solution 3:[3]

Use kill -9 or kill -2 command. To find id of your process use ps aux.

Solution 4:[4]

Had this issue when running in the background on an EC2, rebooting fixed the issue

Solution 5:[5]

On mac terminal after running jupyter notebook it says

Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

I've tried it - it works for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 patapouf_ai
Solution 2
Solution 3 Anton Hulikau
Solution 4 Ryan Charmley
Solution 5 Joe Fagan