50

For example, we'd like to see:

PROCESS       IF       TX       RX       FILE(regular) R/W
prog1         eth0     200kB/s  12kB/s   --            --
              wlan0    12kB/s   100kB/s  --            --
              --       --       --       file1         R
              --       --       --       file2         R
              --       --       --       file3         W
prog2         eth0     0kB/s    200kB/s  --            --
              --       --       --       file4         W
              --       --       --       file5         W

Is this possible? nethogs only shows the TX/RX, while lsof only shows the file accesses.

I'm currently doing a 2-step process like so:

sudo nethogs
sudo lsof -a -d 1-999 -c hogging_program /

Is there a better way?

1

5 Answers 5

43

Try iftop for network and pidstat from sysstat.

Both are probably an easy install (apt-get, etc) for the distribution of your choice.

1
  • 3
    A catch with iftop: make sure you passed it an interface name with -i option. One would expect it listens by default on all interfaces — unfortunately this is not true. Instead it picks a random one, so, depending on your luck, you're likely to get invalid results.
    – Hi-Angel
    Mar 12, 2020 at 6:37
8

atop goes some way to giving you what you want, although it wouldn't be as specific as breaking down I/O by filehandle. To get full networking statistics you have to apply a kernel patch.

5

As far as I know, no. What you're trying to accomplish is possible combining multiple commands as you're currently doing, though I don't know of other apps that would provide you data easier to parse (ed: another answer suggested iftop which I did not know added a pipe-able single line text output mode). With some clever shell scripting, piped data, and a bit of manual formatting, you could get at least close to the output you're looking for.

Your search for something that shows both network and file statistics - which would be provided by two different parts of the operating system - seems to be up against some tenants of 'The UNIX Philosophy:'

  • Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features.
  • Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information.

This is particularly evident in programs that output text, like lsof. You don't usually see *NIX console programs providing a user interface as much as data to be piped into another program, or possibly a script utilizing shell commands like cut to create their own specifically tailored outputs.

Doug McIlroy summarized his earlier statement years later:

Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.

While it may not help you get the formatted output you're looking for, The Art of UNIX Programming is a good read, and where I found sources for those quotes.

4
  • 20
    This does not provide an answer to the question.
    – cat
    Jun 21, 2016 at 20:27
  • Is this possible? -- I believe what you're trying to accomplish is probably best (and as far as I know only) possible combining multiple commands as your currently doing. -- is there a better way? I believe what you're trying is probably best and only possible convincing multiple commands... wiith some clever shell scripting and piped data, you could get the output [formatted the way] you're looking for. -- what question did I miss? might be better answered with a mention of piped shell scripts, but your helpful feedback didn't mention that :p is the proper answer a working script?
    – aquafunk
    Jun 22, 2016 at 0:45
  • 3
    I believe what you're trying to accomplish is probably best described as "answer a question"; not lecture someone on philosophy. Aug 23, 2017 at 17:54
  • Ill put the answer more plainly at the top.Without the philosophy lesson, though, nobody learns why the answer is no, and may wander back into the internet, never understanding the wise words of Linux Torvalds; "The Linux Philosophy is 'Laugh in the face of danger!' Oops. Wrong one. 'Do it yourself.' That's it."
    – aquafunk
    Sep 29, 2017 at 17:41
4

iptraf can be very usefull and finding bandwidth hogs.

1
  • 5
    Adding more info/explanation will make your answer better.
    – mtk
    Mar 18, 2013 at 13:07
1

You may also want to consider nethogs which is an actively maintained project, and the headline is net top tool.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .