-1

I use the simple netstat command "netstat -nltp" which shows me all active TCP connections along with the PID and process name. However even after playing around with parameters, I am unabe to get an important information from the command.

That is:

I want to see the number of packets received and sent from/to this PID I learnt that Recv-Q and Send-Q are not indicative of this. Also, the statistics parameter seems to sum up for all processes. How can I see the packets received and sent to a PID?

Thanks

tweet
  • 51
  • 2
  • 11

2 Answers2

3

Use inner process counters for that:

cat /proc/<PID>/net/netstat
Alexander Yancharuk
  • 13,817
  • 5
  • 55
  • 55
1

You want to do network traffic accounting per process.

There are number of applications that allow you to do that in real-time (i.e: nethogs), but the problem is keeping traffic counters over time.

I would suggest you to do so using iptables, assuming you can clearly distinguish your processes using a network port.

This article is still OK for your use case: https://www.cyberciti.biz/faq/linux-configuring-ip-traffic-accounting/

PS: This sort of questions is best in Server Fault

Alexandre Juma
  • 3,128
  • 1
  • 20
  • 46