I am looking for a reliable solution to do package capture for test automation.
Right now, tcpdump has been used with the following command.
sudo tcpdump -i ens160 -w filename.pcap -G 60 -W 1
I stop tcpdump with:
kill -s SIGINT <pid>
1 out of 20 time tcpdump fails to exit properly, and the pcap file will be damaged.
Is there any way to make sure tcpdump will exit properly?
There are two ways to avoid a truncated dump file:
As suggested by Doug Smythies, use termination signal (
SIGTERM
) instead ofSIGINT
to kill thetcpdump
process:Tell
tcpdump
to write packet directly to file as each packet is saved (option-U
). This way, even using SIGINT, the file will not be truncated. From man tcpdump :