31

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?

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.

  • 7
    This does not provide an answer to the question. – cat Jun 21 '16 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? – overprescribed Jun 22 '16 at 0:45
  • I believe what you're trying to accomplish is probably best described as "answer a question"; not lecture someone on philosophy. – Gardner Bickford Aug 23 '17 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." – overprescribed Sep 29 '17 at 17:41
17

Try iftop for network and pidstat from sysstat.

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

6

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.

2

iptraf can be very usefull and finding bandwidth hogs.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.