Time spent by less command to output output

I have a script that produces a lot of output. The script stops for a few seconds at a point T.

Now I use the command lessto parse the output of the script. Therefore, I perform ./script | less. I will leave it working for enough time for the script to complete execution.

Now I look at the output of the less command by pressing the Pg Down key. Surprisingly, when I scroll at a point Ton the output, I again see a pause of a few seconds.

The script does not expect input and will definitely be completed by the time the output analysis starts less.

Can someone explain how a pause of a few seconds will be noticeable in the output less when the script completes execution?

+5
source share
5 answers

Your script is contacted lessusing a pipe . A pipe is a stream of bytes in memory that connects two endpoints: your script program and a lessformer write to it, the last of which is read.

, , . , , (, ) . 64k Linux. , script , . , script , - write().

? - ; , , , ( ) . less . , .

, , (, G), (, G). , :

./script | less +Gg

, , , script , . less . ( , ./script ), :

 ./script >x & less x ; rm x
+8

, script , less .

+2

. script , - .

, , , less +G, , , 1G.

+2

For some background information, there is also a good article by Alexander Sandler entitled "How less it processes its input"!

http://www.alexonlinux.com/how-less-processes-its-input

+2
source
Can I externally enforce line buffering on the script? 
Is there an off the shelf pseudo tty utility I could use? 

You can try to use the command scriptto enable line buffering output mode.

script -q /dev/null ./script | less      # FreeBSD, Mac OS X
script -c "./script" /dev/null | less    # Linux

For more alternatives in this regard, see Disable tube buffering .

0
source

All Articles