nohup 进程的进程 ID 不断更新 - 无法终止进程

Process ID of nohup process continually updating - cant kill process

我正在尝试终止 EC2 实例中的 nohup 进程,但到目前为止没有成功。我正在尝试获取进程 ID (PID),然后在终端中将其与 kill 命令一起使用,如下所示:

[ec2-user@ip-myip ~]$ ps -ef |grep nohup 
ec2-user 16580 16153  0 19:50 pts/0    00:00:00 grep --color=auto nohup

列,(我相信)它们是:

UID        PID  PPID  C STIME TTY          TIME CMD
ec2-user 16580 16153  0 19:50 pts/0    00:00:00 grep --color=auto nohup

但是,每次我尝试终止进程时,我都会收到一个错误,提示 PID 不存在,这似乎是因为 PID 已更改。这是我在命令行中 运行 进入的序列:

// first try, grab the PID and kill
[ec2-user@ip-myip ~]$ ps -ef |grep nohup 
ec2-user 16580 16153  0 19:50 pts/0    00:00:00 grep --color=auto nohup

[ec2-user@ip-172-31-41-213 ~]$ kill 16580
-bash: kill: (16580) - No such process


// ?? - check for correct PID again, and try to kill again
[ec2-user@ip-myip ~]$ ps -ef |grep nohup 
ec2-user 16583 16153  0 19:50 pts/0    00:00:00 grep --color=auto nohup

[ec2-user@ip-172-31-41-213 ~]$ kill 16583
-bash: kill: (16583) - No such process

// try 3rd time, kill 1 PID up
[ec2-user@ip-myip ~]$ ps -ef |grep nohup 
ec2-user 16584 16153  0 19:50 pts/0    00:00:00 grep --color=auto nohup

[ec2-user@ip-myip ~]$ kill 16585
-bash: kill: (16585) - No such process

现在这对我来说非常困难,因为我需要 kill/restart 这个 nohup 过程。任何帮助表示赞赏!

编辑 - 我尝试使用这种方法来终止进程,因为它作为答案发布在该线程 (Prevent row names to be written to file when using write.csv) 中,并且是评分第二高的答案。

非常非常糟糕的问题...

  1. 你正试图杀死你 grep 进程...

    ec2-user 16580 16153  0 19:50 pts/0    00:00:00 grep --color=auto nohup
    

命令是grep --color=auto nohup

  1. 我不确定你能否杀死 nohup

nohup 将以特定方式 运行 您的命令。但启动后,nohup 进程终止。

如果你想 grep ps 输出:

ps -ef | grep '[n]ohup'

pgrep -fl nohup

因为您试图杀死的不是 nohup pid,而是 grep 本身...