首先,是的,我已经看到了这个问题:
那里的答案是不正确的,不起作用.我已经相应地投票和评论.
当我用ps aux |列出时,我要杀死的进程看起来像这样grep page.py:
apache 424 0.0 0.1 6996 4564 ? S 07:02 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 2686 0.0 0.1 7000 3460 ? S Sep10 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 2926 0.0 0.0 6996 1404 ? S Sep02 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 7398 0.0 0.0 6996 1400 ? S Sep01 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 9423 0.0 0.1 6996 3824 ? S Sep10 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 11022 0.0 0.0 7004 1400 ? S Sep01 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 15343 0.0 0.1 7004 3788 ? S Sep09 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 15364 0.0 0.1 7004 3792 ? S Sep09 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 15397 0.0 0.1 6996 3788 ? S Sep09 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 16817 0.0 0.1 7000 3788 ? S Sep09 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 17590 0.0 0.0 7000 1432 ? S Sep07 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 24448 0.0 0.0 7000 1432 ? S Sep07 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py apache 30361 0.0 0.1 6996 3776 ? S Sep09 0:00 /usr/bin/python2.6 /u/apps/pysnpp/current/bin/page.py
我正在设置一个简单的每日cron,可以找到并杀死任何超过一小时的page.py进程.
上述问题的接受答案不起作用,因为它与一系列时间不匹配,它只是匹配从7天到7天23小时59分59秒运行的过程.我不想杀死已经运行1-2小时的进程,而是杀死超过1小时的进程.
使用find的上述问题的另一个答案不起作用,至少在Gentoo或CentOS 5.4上没有效果,它会发出警告,或者如果遵循所述警告的建议则不返回任何内容.
解决方法
GNU Killall可以使用其进程名杀死超过给定年龄的进程.
if [[ "$(uname)" = "Linux" ]];then killall --older-than 1h page.py;fi