How can I monitor network I/O usage per process under Linux?

Solution 1:

nethogs looks like it will do what you want.

EDIT: I needed to install ncurses-devel, libpcap and libpcap-devel to build.

Solution 2:

To find what connections are associated with each process, use lsof. For example:

lsof | grep TCP

That will give you a list of connections, like this:

bash    10887 luke    3u     IPv4 44638801      0t0      TCP> (ESTABLISHED)
bash    10913 luke    3u     IPv4 44638905      0t0      TCP> (ESTABLISHED)
ssh     10935 luke    3u     IPv4 44639001      0t0      TCP> (ESTABLISHED)
ssh     10935 luke    4u     IPv4 44639008      0t0      TCP> (ESTABLISHED)
bash    10938 luke    3u     IPv4 44639107      0t0      TCP> (ESTABLISHED)

From there, you should be able to find out about each connection individually using the tools you mentioned (iftop, iptraf). You could build a small script to aggregate the specific data that you're looking for.