0
嗨我寫了一個腳本,該腳本以前使用'snoop'命令正常工作。該腳本在腳本中讓孩子啓動tcpdump。當我必須停止轉儲時,我會殺死孩子,但是當我查看wireshark中生成的pcap時,它會顯示錯誤「捕獲文件似乎在數據包中間被縮短了」。我的命令是在Linux上捕獲tcpdump跟蹤的Perl腳本
my $snoopAPP = &startService("tcpdump -w /tmp/app.pcap -i bond0>/dev/null 2>&1" , '');
kill 9, -$snoopAPP;waitpid $snoopAPP, 0;
sub startService(){
#runs a program in background and returns PID which can be used later to kill the process
#arguments are 1, path , 2nd the name of the file
my $processPath = $_[0];chomp($processPath);
if ($_[1] ne ''){$processPath = $processPath . " >$path/$_[1].log";}
print "\nStarting ... \n-- $processPath\n";
my $pid = fork();
die "unable to fork $processPath: $!" unless defined($pid);
if (!$pid) { # child
setpgrp(0, 0);
exec("$processPath");
die "\nunable to exec: $!\n";
exit;
}
print " ---- PID: $pid\n";
return $pid;
}
另一篇文章建議等待tcpdump的退出,我是做了,但它仍然會導致同樣的錯誤消息。
很好..它的工作.. – Muzammil