我想使用 perl 脚本在 linux shell 上将 tcpdump 作为后台进程启动,但我必须解析输出,然后我需要终止进程。我该怎么做?
最佳答案
在 Unix 中,传统的方法是编写非常专业的小程序并将它们通过管道连接在一起。为什么不直接将 tcpdump 输出通过管道传输到脚本标准输入中?
我的 perl 有点生疏了:
$| = 1;
my $pid = open(DUMP, "tcpdump -i eth1 -l -n 2>\&1 |");
while(<DUMP>) {
# do something
if($some_condition) {
`kill $pid`;
last;
}
}
关于linux - 如何在 linux 上运行后台进程,然后在解析输出后将其终止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12812611/