免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2801 | 回复: 7

[系统管理] ps 进程时 会多一个进程 多的那个哪里来的 [复制链接]

论坛徽章:
0
发表于 2018-03-15 10:53 |显示全部楼层
#!/bin/sh
program_name="testkill_servcie"

kill_process_noinclde_self()
{
        selfId=$$

        processname=${1}

        if [ -z "${processname}" ] ;then
            return
        fi

     ## id=`ps aux|grep -v grep|grep "${processname}"|tr -s ' '|cut -d ' ' -f 2|grep -v "^${selfId}$"`
        id=`ps aux|grep -v grep|grep "${processname}"|grep -v "^${selfId}$"`
       
        #echo "ps aux|grep -v grep|grep \"${processname}\"|tr -s ' '|cut -d ' ' -f 2|grep -v \"^${selfId}$\"|grep -v grep"
        echo "id=${id}"
        return
       
        while [  -n "${id}" ]; do
             kill -9  ${id}
             id=`ps aux|grep -v grep|grep "${processname}"|tr -s ' '|cut -d ' ' -f 2|grep -v "^${selfId}$"`
        done
}

fun_main()
{
  cmd_param=$1;

  case "${cmd_param}" in
        "test")
                echo "curretn $$"
                kill_process_noinclde_self  "${program_name}.sh test"
                sleep 60
                ;;
        *)
                ;;
        esac
}

echo "start prog"

fun_main $1

echo "success"


测试 testkill_servcie.sh test

[root@DataMonitorDB script]# ./testkill_servcie.sh test
start prog
curretn 4424
fun_stop_process :start testkill_servcie.sh test 4424
id=root      4424  0.0  0.0 106152  1328 pts/0    S+   10:33   0:00 /bin/sh ./testkill_servcie.sh test 如果加上|tr -s ' '|cut -d ' ' -f 2|grep -v "^${selfId}$"  那这行不出来
root      4425  0.0  0.0 106152   576 pts/0    S+   10:33   0:00 /bin/sh ./testkill_servcie.sh test     不管哪种情况,都会冒个这条    这里那来的


ps aux|grep -v grep|grep \"${processname}\"|tr -s ' '|cut -d ' ' -f 2|grep -v \"^${selfId}$\"|grep -v grep  这个样子还是一样

论坛徽章:
6
程序设计版块每日发帖之星
日期:2016-05-11 06:20:00操作系统版块每日发帖之星
日期:2016-05-12 06:20:00每日论坛发贴之星
日期:2016-05-12 06:20:00操作系统版块每日发帖之星
日期:2016-05-14 06:20:00程序设计版块每日发帖之星
日期:2016-05-31 06:20:00每日论坛发贴之星
日期:2016-05-31 06:20:00
发表于 2018-03-15 11:14 |显示全部楼层
回复 1# asdmusic

./testkill_servcie.sh test

[ba]sh(ell) ./testkill_servcie.sh test
运行的na条command

论坛徽章:
0
发表于 2018-03-15 11:21 |显示全部楼层
-rwxrwxrwx 1 root root 1051 Mar 15  2018 testkill_servcie.sh
[root@DataMonitorDB script]# ./testkill_servcie.sh test
start prog
curretn 4689
id=root      4689  0.0  0.0 106152  1292 pts/0    S+   11:19   0:00 /bin/sh ./testkill_servcie.sh test
root      4690  0.0  0.0 106152   540 pts/0    S+   11:19   0:00 /bin/sh ./testkill_servcie.sh test

我这边有东西呀


论坛徽章:
0
发表于 2018-03-15 12:13 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
发表于 2018-03-15 12:15 |显示全部楼层
我要把我本身进程排除掉

论坛徽章:
0
发表于 2018-03-15 12:40 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
24
申猴
日期:2014-10-10 15:56:39射手座
日期:2014-10-10 15:57:18黑曼巴
日期:2018-05-14 11:05:122016科比退役纪念章
日期:2018-05-14 11:05:0715-16赛季CBA联赛之北控
日期:2018-05-14 11:05:0015-16赛季CBA联赛之江苏
日期:2017-02-27 18:11:0715-16赛季CBA联赛之上海
日期:2018-08-15 09:48:5415-16赛季CBA联赛之佛山
日期:2018-07-20 17:14:2315-16赛季CBA联赛之佛山
日期:2019-09-10 18:08:4615-16赛季CBA联赛之山西
日期:2020-03-26 09:40:5115-16赛季CBA联赛之佛山
日期:2020-05-08 09:03:54
发表于 2018-03-15 15:32 |显示全部楼层
本帖最后由 chengchow 于 2018-03-15 15:33 编辑

写脚本需要处理进程的一个坑
我要处理进程aaaaa

写个脚本叫aaaaa.sh

好了处理的时候始终多一个进程

一个是需要处理的aaaaa的进程
一个是你脚本跑的时候产生的进程aaaaa.sh

怎么办?把你脚本改个名字

论坛徽章:
0
发表于 2018-03-15 16:49 |显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP