为什么我不能杀死 NOHUP 进程?

The*_*One 2 process kill nohup

因此,为了让我的简单博客永久运行,我使用了以下nohup命令:

nohup python manage.py runserver 0.0.0.0:8000
Run Code Online (Sandbox Code Playgroud)

一切正常,即使我退出终端,我的博客仍在运行。但是现在我不想再运行它了,所以我试图杀死它,但出现错误:

# ps aux | grep nohup
root     23427  0.0  0.0 103308   860 pts/1    S+   11:56   0:00 grep nohup
# kill -9 23427
bash: kill: (23427) - No such process
Run Code Online (Sandbox Code Playgroud)

当然,我的博客还在继续运行,所以我不明白刚刚发生了什么。有没有办法处理这个问题?

Dop*_*oti 11

你没有nohup流程。您的搜索找到了一个grep正在搜索的实例nohup,但是当您收到下一个提示时,该grep过程已经终止。你实际上是在寻找一个python实例。

ps aux | grep python | grep manage.py # This will show you the process you're looking for
kill $(ps aux | grep python | grep manage.py | awk '{print $2}') # This will kill it.
Run Code Online (Sandbox Code Playgroud)

  • 很高兴为您服务。 (2认同)
  • 或者只是`kill $(ps aux | awk '/ [m]anage.py/ {print $2}')`。更好的是,在 `screen` 或 `tmux` 或类似内容中运行 `manage.py`,而不是使用 `nohup`。然后,如果/当您需要时,您可以轻松地重新附加到`screen`/`tmux`/任何会话。您可以根据需要多次附加/分离/重新附加。 (2认同)