[英]Kill processes older that one day by its name
I have a question much related to the problem. 我有一个与此问题密切相关的问题。 Here's my code:
这是我的代码:
ps -eo pid,etime,cmd|grep ${1}|grep -v grep|awk '{if ($2>="23:59:59") print $1}'|xargs kill -9
I am trying to kill all processes with specific name which etime is more than a day. 我试图杀死所有使用etime超过一天的特定名称的进程。 It worked well that way until i was told that the script cannot kill processes that represent date in a format like: 1-23:00:00.
直到我被告知该脚本无法终止以1-23:00:00之类的格式表示日期的进程之前,这种方式一直有效。
Changing variable $2 in awk procedure to 1-00:00:00 kills all processes with given name. 在awk过程中将变量$ 2更改为1-00:00:00将杀死具有给定名称的所有进程。 Can you give me a hint how to format etime properly?
您能提示我如何正确格式化etime吗?
instead of changing the awk script, I suggest changing ps
option etime
into etimes
. 建议不要将
ps
选项etime
更改为etimes
,而不是更改awk脚本。
With etimes
you got the lifetime in seconds . 使用
etimes
您可以以秒为单位获得生命。 you are free to choose to kill or not kill if the value > or <
a certain value. 如果值
> or <
一定值,则可以随意选择杀死还是不杀死。 even, $2>=somevalue1 && $2<= somevalue2
甚至
$2>=somevalue1 && $2<= somevalue2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.