views:

27

answers:

1

I want to know how much network traffic is consumed by each process.

I would prefer for a crossplatform solution but I guess this is not possible, so I am searching for a solution which works on MacOSX right now.

The solution should be lightweight. I want to run it in background and it should analyse all running processes.

(Stupid disclaimer: As I am asking on Stackoverflow, I am implying by that that I am asking for programmatically solutions here. The same question on Superuser means something different.)

+2  A: 

nethogs

On Ubuntu:

sudo apt-get install nethogs
sudo nethogs

nethogs uses libpcap. To get the sources on Ubuntu and learn from that:

apt-get source nethogs

In particular the decpcap.c file is probably relevant.

And these links might be helpful:

kanaka