那么问题来了,如何将该脚本在后台中kill呢?如果直接kill子进程,那么将会子子孙孙无穷尽。。。。。显然这个方法是行不通的!
使用如下命令:
ps -ef | grep “后台运行的脚本名”
会打印出相关信息
ps -ef | grep disk_test.sh user 2326 17774 0 16:59 pts/1 00:00:00 grep --color=auto disk_test.sh user 21902 21889 0 16:37 ? 00:00:00 /bin/sh -c /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 21905 21902 10 16:37 ? 00:02:22 /bin/sh /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 25068 1 10 16:41 ? 00:01:54 /bin/sh /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 29020 28977 0 16:43 ? 00:00:00 /bin/sh -c /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 29032 29020 10 16:43 ? 00:01:43 /bin/sh /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 30307 30305 0 16:36 ? 00:00:00 /bin/sh -c /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 30309 30307 10 16:36 ? 00:02:28 /bin/sh /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 30752 30719 0 16:40 ? 00:00:00 /bin/sh -c /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh user 30758 30752 10 16:40 ? 00:02:00 /bin/sh /home_b/nfsroot/user/chip_rootfs/root-uclibc-toolchain/system/disk_test.sh
使用kill将相关的进程ID删除,然后在top命令下看到运行脚本已经关闭了!