Article 54P87 Programatically retrieve total number of bytes sent & received for (current) process

Programatically retrieve total number of bytes sent & received for (current) process

by
vpseg
from LinuxQuestions.org on (#54P87)
I need to retrieve the total number of bytes sent and received by a Python process/program. I prefer to do so within the Python program, but any working solution would be helpful.

What I've tried:
Nethogs: Not preferred as I cannot get information from it programatically
Wireshark: has a GUI
tshark: writing filters for all IPs used by the process is not ideal
Netfilter rules: see tshark
/proc/PID/net/dev: reading file while using ping shows all zeros; reading repeatedly until process terminates is not ideal

Please let me know.latest?d=yIl2AUoC8zA latest?i=oef0TqEEXP0:HPvzBBPn_dE:F7zBnMy latest?i=oef0TqEEXP0:HPvzBBPn_dE:V_sGLiP latest?d=qj6IDK7rITs latest?i=oef0TqEEXP0:HPvzBBPn_dE:gIN9vFwoef0TqEEXP0
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments