我在服务器上运行nohup进程。当我试图杀死它,我的油灰控制台关闭。

这是我如何试图找到进程ID:

ps -ef |grep nohup 

这是杀人的命令

 kill -9 1787 787

当前回答

这在Ubuntu中是有效的

输入这个来找出PID

ps aux | grep java

所有有关java的运行过程将被显示

对我来说

johnjoe      3315  9.1  4.0 1465240 335728 ?      Sl   09:42   3:19 java -jar batch.jar

现在杀死它杀死-9 3315

僵尸进程终于停止。

其他回答

When using nohup and you put the task in the background, the background operator (&) will give you the PID at the command prompt. If your plan is to manually manage the process, you can save that PID and use it later to kill the process if needed, via kill PID or kill -9 PID (if you need to force kill). Alternatively, you can find the PID later on by ps -ef | grep "command name" and locate the PID from there. Note that nohup keyword/command itself does not appear in the ps output for the command in question.

如果你使用一个脚本,你可以在脚本中做这样的事情:

nohup my_command > my.log 2>&1 &
echo $! > save_pid.txt

This will run my_command saving all output into my.log (in a script, $! represents the PID of the last process executed). The 2 is the file descriptor for standard error (stderr) and 2>&1 tells the shell to route standard error output to the standard output (file descriptor 1). It requires &1 so that the shell knows it's a file descriptor in that context instead of just a file named 1. The 2>&1 is needed to capture any error messages that normally are written to standard error into our my.log file (which is coming from standard output). See I/O Redirection for more details on handling I/O redirection with the shell.

如果该命令定期发送输出,您可以偶尔使用tail my.log检查输出,或者如果您希望“实时”跟踪它,则可以使用tail -f my.log。最后,如果你需要终止进程,你可以通过:

kill -9 `cat save_pid.txt`
rm save_pid.txt

我在VPS服务器上使用red hat linux(并通过SSH - putty),对我来说,以下工作:

首先,列出所有正在运行的进程:

ps -ef

然后在第一列中找到您的用户名;我发现它有以下三次:

一个是SSH连接 第二个是FTP连接 最后一个是nohup过程

然后在第二列中,你可以找到nohup进程的PID,你只需要输入:

kill PID 

(当然是用nohup进程的PID替换PID)

就是这样!

我希望这个答案对一些人有用,我也是bash和SSH的新手,但在这里找到了我需要的95%的知识:)

这适用于mi fine在mac上

kill -9 `ps -ef | awk '/nohup/{ print \$2 }'`

你可以试试

kill -9 `pgrep [command name]`

今天我遇到了同样的问题。因为是很久以前的事了,我完全忘了我在什么时候用了哪个命令。我尝试了三种方法:

Using the STIME shown in ps -ef command. This shows the time you start your process, and it's very likely that you nohup you command just before you close ssh(depends on you) . Unfortunately I don't think the latest command is the command I run using nohup, so this doesn't work for me. Second is the PPID, also shown in ps -ef command. It means Parent Process ID, the ID of process that creates the process. The ppid is 1 in ubuntu for process that using nohup to run. Then you can use ps --ppid "1" to get the list, and check TIME(the total CPU time your process use) or CMD to find the process's PID. Use lsof -i:port if the process occupy some ports, and you will get the command. Then just like the answer above, use ps -ef | grep command and you will get the PID.

一旦找到进程的PID,就可以使用kill PID来终止进程。