【发布时间】:2020-06-23 03:45:37
【问题描述】:
这可能是一个非常基本的问题,但我在互联网上的任何地方都找不到。 假设我有一个包含此代码的名为 test 的文件
echo hello
sleep 10
echo hello
sleep 10
echo hello
sleep 10
我将如何通过服务器中的另一个终端杀死该程序?
【问题讨论】:
这可能是一个非常基本的问题,但我在互联网上的任何地方都找不到。 假设我有一个包含此代码的名为 test 的文件
echo hello
sleep 10
echo hello
sleep 10
echo hello
sleep 10
我将如何通过服务器中的另一个终端杀死该程序?
【问题讨论】:
我假设文件是 test.sh
你可以这样做:
ps -x | grep ./test.sh
这将显示流程:
11164 pts/1 S+ 0:00 /usr/bin/bash ./test.sh
and a second process that will be a grep process, you won't be able to kill the process that has the word grep in it because that process completes right away
现在您可以使用 PID 终止进程:
kill 11164
【讨论】:
您的脚本文件名是test。
所以,在另一个终端,你可以执行ps aux | grep test。
然后你可以得到test的PID,它位于第二列。
然后,执行kill -9 <PID>。
【讨论】:
kill时你确定test.sh还没有完成吗?
Ctrl c
按此键,您可以从终端中终止该程序。 你可以从你的主终端中杀死这个程序,你首先要执行它。
【讨论】: