Why does "slabtop -o" only return the first 23 lines when the command is piped?

slabtop, even with -o, always limits itself to one screenful of output. It normally does so by asking the terminal what its size is, but when its standard output isn’t a terminal, it assumes that the screen is 80 columns by 24 rows and only outputs 23 rows (to avoid any scrolling).

This since has been fixed, and the fix is present in procps-ng 3.3.13 and later.


It's just hard-coded to work this way when output isn't a terminal.

if you still want to use redirection and get more rows, you can use script to trick slabtop into thinking it's output is being printed to the terminal. You can add stty on top of that to change pseudo-terminal parameters and set your own limit for output lines.

# slabtop -o | wc -l
23
# script -q -c "slabtop -o" /dev/null | wc -l
46
# script -q -c "stty rows 999; slabtop -o" /dev/null | wc -l
147

Alternatively, you can just get your information directly from /proc/slabinfo file, which is also used by slabtop itself.

Tags:

Linux