我正在写一个有趣的剧本,它将杀死PID。
我找到了一个与我有关的好答案:https://stackoverflow.com/a/46541018/8863970
但是,在我的情况下,第一步是Get running processes
,我有两个过程,如下所示:
# when i do: ps -ef | grep appp.py
ubuntu 17765 1 2 12:14 pts/0 00:00:04 python appp.py
ubuntu 17784 17765 4 12:15 pts/0 00:00:05 /home/ubuntu/venvs/myvnv/bin/python /home/ubuntu/deploy/appp.py
ubuntu 17844 14784 0 12:17 pts/0 00:00:00 grep --color=auto appp.py
它杀死17765
,然后失败:
failed: [10.10.1.1] (item=17784) => {"ansible_loop_var": "item", "changed": true, "cmd": "kill 17784", "delta": "0:00:00.002196", "end": "2020-04-26 12:23:22.833284", "item": "17784", "msg": "non-zero return code", "rc": 1, "start": "2020-04-26 12:23:22.831088", "stderr": "/bin/sh: 1: kill: No such process", "stderr_lines": ["/bin/sh: 1: kill: No such process"], "stdout": "", "stdout_lines": []}
意思是...找不到要杀死的17784
。>
问题是:如何使用ps grep
仅获取父PID(17784),然后将其传递来杀死它?
我正在写一个有趣的剧本,它将杀死PID。我找到了一个与我相关的好答案:https://stackoverflow.com/a/46541018/8863970但是,第一步是Get running ...
交到最后| grep -v grep