如何找出一个后台运行的Shell脚本的进程并终止它
发表于 : 2012-07-07 19:27
ps aux|grep autojoin.sh找不到正在运行它的bash饿。。。YeLee 写了:ps -aux能找到的吧,你前面少了点东西嘛,我在这边测试都没有问题,不过,后台也可以fg过来的嘛。![]()
![]()
综合大家的意见我还是用的pmshou 写了:如果是用的bash,可以:pgrep bash
代码: 全选
grep aux|grep bash
代码: 全选
work@BD-MTC-PC-Router01:~$ ps aux|grep bash
work 20750 0.0 0.3 23648 7672 pts/2 Ss+ 19:12 0:00 -bash
work 20915 0.0 0.2 27276 4392 pts/1 Ss+ 19:23 0:00 bash
work 21426 0.0 0.1 27276 3332 pts/1 S 20:50 0:00 bash
work 21437 0.0 0.2 27208 4268 pts/4 Ss 20:51 0:00 bash
work 21569 0.0 0.1 27276 3332 pts/1 S 20:53 0:00 bash
work 21753 0.0 0.0 13576 924 pts/4 S+ 20:56 0:00 grep --color=auto bash
试过了,不行。YeLee 写了:代码: 全选
for i in $(ps aux|grep bash|awk '{print $2}');cat /proc/$i/cmdline && echo $i
![]()
![]()
馊主意,检查命令行的。
代码: 全选
work@BD-MTC-PC-Router01:~/PannadScript$ ./checkBash.sh
-bash20750
bash20915
bash21426
bash21437
bash21569
bash24009
cat: /proc/24010/cmdline: No such file or directory
cat: /proc/24012/cmdline: No such file or directory
代码: 全选
ps aux|grep autoprint.sh
pgrep autoprint.sh
skill -n autoprint.sh
pkill autoprint.sh
skill autoprint.sh
killall autoprint.sh
代码: 全选
% sleep 1d &
[1] 31742
[Login] cfy at cfy-notebook in /tmp/new
% jobs
[1] + running sleep 1d
[Login] cfy at cfy-notebook in /tmp/new
% kill %1
[Login] cfy at cfy-notebook in /tmp/new
%
[1] + terminated sleep 1d
[Login] cfy at cfy-notebook in /tmp/new
%