3

While i pipe nethogs it takes too much delay for the output ( About 5-200 sec instead of 1 sec depend on pipe,cmd etc). Nethogs print output in every second.

For the sake of simplicity consider the following command ( it takes abt 5 sec )

sudo nethogs ppp0 | grep e | grep e |grep c

I belive it due to the buffering in pipe.

How can i avoid the delay (In general or in the case of nethogs)???

Seth
  • 57,282
  • 43
  • 144
  • 200
totti
  • 6,768
  • 4
  • 38
  • 48

1 Answers1

0

Finally I found it. It can be done simply using perl.

perl -le 'open(P," top  |");  $|=1; while(<P>){ print }'

Take the example of

top | grep i | grep id
perl -le 'open(P," top  |");  $|=1; while(<P>){ print "------","$_"; }' | grep i | grep id

For nethogs

perl -le 'open(P,"sudo nethogs ppp0 |");  $|=1; while(<P>){ print "------","$_"; }' |  grep e | grep e |grep c
You'reAGitForNotUsingGit
  • 14,669
  • 9
  • 48
  • 83
totti
  • 6,768
  • 4
  • 38
  • 48
  • Maybe you can use `stdbuf` or `unbuffer` commands. I'm [on a related situation](https://askubuntu.com/q/1122816/349837) – Pablo Bianchi Mar 05 '19 at 06:36