免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: hanzq001
打印 上一主题 下一主题

急!删除5秒钟以前产生的进程abc,怎么写?谢谢 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-12-17 12:50 |只看该作者
我觉得楼主的要求用 perl方便一点,shell的数组功能不是很强大


while(1)
{
  $pid=`ps -ef|grep...................`;  
  $a{$pid}=time()  if ( ! exists($a{$pid});
if (time()-$a{$pid} > 5)
{
  kill 9,$pid;
}
sleep(1);
}

论坛徽章:
0
12 [报告]
发表于 2008-12-17 13:49 |只看该作者
花了些时间,如果还行或不行的话,告诉我,谢

  1. #!/bin/bash
  2. # killptime.sh
  3. # Wed 17 Dec 2008 01:41:38 PM h

  4. declare -a arr

  5. if [ $# -lt 2 ]
  6. then
  7. echo "Usage: $0 name running_time escape_pid"#英文不好
  8. echo "       name:         the name of processes you want to kill" #进程名
  9. echo "       running_time: run more than this will be killed,use seconds as unit" #运行时间
  10. echo "       escape_pid:   the pid of which you do not want to kill"#不想杀的进程
  11. echo "                     all will be killed ,if no special"#不指定,全杀
  12. exit 1
  13. fi

  14. while true
  15. do
  16. arr=( $(ps h -C "$1" -o pid,start,comm) )
  17. i=0
  18. while [[ ${arr[$i]} != "" ]]
  19. do
  20.     t_time=$((`date +%s`-`date -d"${arr[$i+1]}" +%s`))
  21.     echo $t_time

  22.     if [[ $t_time -gt $2 && x$3 != x${arr[$i]} ]]
  23.     then
  24.         kill -9 ${arr[$i]}
  25.     fi
  26. #    echo ${arr[$i]}
  27. #    echo ${arr[$i+1]}
  28. #    echo ${arr[$i+2]}
  29.     ((i += 3))
  30. done
  31. sleep 5   #这个值是不是也由参数指定好些?
  32. done
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP