如何释放笔记本服务器停止后持有的端口?

时间:2016-01-27 08:47:35

标签: port ipython-notebook jupyter jupyter-notebook

我在AWS实例(Redhat Linux服务器)上启动jupyter笔记本服务器以通过https连接。在配置文件中,我应该在端口9999上。但是当我使用Ctrl-C停止并重新启动进程时,端口没有被释放,如下所示。

[user@ip-xxx-xx-xx-xxx notebook]$ [I 08:39:27.901 NotebookApp] The port 9999 is already in use, trying another random port.
[I 08:39:27.901 NotebookApp] The port 10000 is already in use, trying another random port.
[I 08:39:27.902 NotebookApp] The port 10001 is already in use, trying another random port.
[I 08:39:27.905 NotebookApp] Serving notebooks from local directory: /home/user/docs/notebook
[I 08:39:27.905 NotebookApp] 0 active kernels
[I 08:39:27.905 NotebookApp] The Jupyter Notebook is running at: https://[all ip addresses on your system]:10002/
[I 08:39:27.905 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

顺便说一句,那些"随机端口"不要随便看我。

1 个答案:

答案 0 :(得分:6)

有时服务的stop命令不会返回任何错误并删除进程的pid文件,但实际上并不会终止进程本身。

您可以通过运行stop命令然后

来检查进程是否仍在运行
ps aux | grep -i notebook

netstat -tlnp | grep <portNumber>

正如您所说,您可以手动终止进程,也可以修复stop脚本(通常是/etc/init.d/serviceName+d)。进程未被杀死的原因通常(并非总是)链接到执行命令的用户所拥有的权限