使用awk有条件地杀死进程 [英] Conditionally killing a process using awk

查看:159
本文介绍了使用awk有条件地杀死进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们,



我正在尝试结合几个awk命令而我没有运气。如果在一段时间内没有一定量的下载流量,那么这个想法就是杀死一个进程。



任何帮助都会受到赞赏。



我尝试了什么:



我可以得到以下信息来正确查找正在运行的qbittorrent进程的PID:

Hi folks,

I'm trying to combine a couple of awk commands and I'm having no luck. The idea is to kill a process if there has been less that a certain amount of download traffic within a certain period of time.

Any help would be appreciated.

What I have tried:

I can get the following to properly find the PID of a running qbittorrent process:

echo $( ps aux | grep "[q]bittorrent" | awk '{ print $2 }' )



以下将告诉我过去几秒内是否有低下载活动:


And the following will tell me if there has been low download activity over the last few seconds:

collectl -c1 -i5 -sn | awk 'NF==4 && $2<200  { print $1 }'

输出是过去5秒内下载的KB数量。



现在我要结合这些 - 在第二个命令中用kill替换 print $ 1 ,然后输出第一个命令。



我尝试了几种变体,例如

The output is the amount of KB downloaded in last 5 seconds.

Now I want to combine these - replacing the print $1 in the second command with "kill" followed by the output of the first command.

I've tried several variations, such as

sudo $( collectl -c1 -i5 -sn | awk 'NF==4 && $2<20 { print "kill " $( ps aux | grep "[q]bittorrent" | awk '{ print $2 }' ) }' )

但无济于事。

推荐答案

(ps aux | grep[q] bittorrent| awk'{print
( ps aux | grep "[q]bittorrent" | awk '{ print


2}')



以下将告诉我过去几秒内是否有低下载活动:


And the following will tell me if there has been low download activity over the last few seconds:

collectl -c1 -i5 -sn | awk 'NF==4 &&


2< 200 {print
2<200 { print


这篇关于使用awk有条件地杀死进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆