Bug 2054864

Summary: top does not restrict LINES=
Product: Red Hat Enterprise Linux 7 Reporter: Donald Berry <dberry>
Component: procps-ngAssignee: Jan Rybar <jrybar>
Status: CLOSED WONTFIX QA Contact: qe-baseos-daemons
Severity: low Docs Contact:
Priority: unspecified    
Version: 7.9   
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-08-15 07:28:27 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Donald Berry 2022-02-15 20:42:43 UTC
Description of problem:

Passing LINES= to top in batch mode with -w should restrict the number of lines of output. It doesn't.

[dberry@t580 ~]$ ssh root@el7a
root@el7a's password: 
Last login: Thu Feb 10 15:00:26 2022 from t580
[root@el7a ~]# LINES=10 top -b -w
top - 15:04:32 up 5 days, 4 min,  2 users,  load average: 0.00, 0.01, 0.05
Tasks: 194 total,   2 running, 192 sleeping,   0 stopped,   0 zombie
%Cpu(s): 17.6 us,  5.9 sy,  0.0 ni, 76.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1881992 total,   729452 free,   616116 used,   536424 buff/cache
KiB Swap:  1048572 total,  1047776 free,      796 used.  1103124 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
 1665 don       20   0 3001044 141160  21208 S  6.2  7.5   2:48.07 gnome-shell
    1 root      20   0  191268   3740   2188 S  0.0  0.2   0:03.18 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.01 kthreadd
    4 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H
    6 root      20   0       0      0      0 S  0.0  0.0   0:01.49 ksoftirqd/0
    7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      20   0       0      0      0 R  0.0  0.0   0:05.39 rcu_sched
   10 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 lru-add-drain
   11 root      rt   0       0      0      0 S  0.0  0.0   0:01.93 watchdog/0
   13 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   14 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   15 root      20   0       0      0      0 S  0.0  0.0   0:00.14 khungtaskd
   16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   19 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   20 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset
   21 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kblockd
   22 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 md
   23 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 edac-poller
...

[root@el7a ~]# man top
...
       -w  :Output-width-override as:  -w [ number ]
            In Batch mode, when used without an argument top will format output using the COLUMNS= and LINES= environment variables, if set.

It works fine in RHEL 8 and Fedora 35:

[dberry@t580 ~]$ ssh root@el8a
Last login: Mon Jan 31 11:29:53 2022 from 192.168.122.1
[root@el8a ~]# LINES=10 top -b -w
top - 15:05:59 up 0 min,  1 user,  load average: 2.14, 0.56, 0.19
Tasks: 137 total,   1 running, 136 sleeping,   0 stopped,   0 zombie
%Cpu(s):100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   1818.9 total,   1355.0 free,    189.1 used,    274.8 buff/cache
MiB Swap:   1024.0 total,   1024.0 free,      0.0 used.   1458.3 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   5096 root      20   0  426656  67308   2480 S  99.9   3.6   0:10.67 mksquashfs
      1 root      20   0   94788  10568   8204 S   0.0   0.6   0:01.51 systemd
      2 root      20   0       0      0      0 S   0.0   0.0   0:00.00 kthreadd

top - 15:06:02 up 0 min,  1 user,  load average: 2.13, 0.59, 0.20
Tasks: 137 total,   2 running, 135 sleeping,   0 stopped,   0 zombie
%Cpu(s): 97.4 us,  1.7 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.7 hi,  0.0 si,  0.3 st
MiB Mem :   1818.9 total,   1350.9 free,    190.7 used,    277.2 buff/cache
MiB Swap:   1024.0 total,   1024.0 free,      0.0 used.   1456.6 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   5096 root      20   0  428960  69156   2480 S  99.0   3.7   0:13.64 mksquashfs
    714 root      20   0       0      0      0 I   0.3   0.0   0:00.06 kworker/0:5-events_power_efficient
      1 root      20   0   94788  10568   8204 S   0.0   0.6   0:01.51 systemd^C
[root@el8a ~]# 

[dberry@t580 ~]$ cat /etc/fedora-release 
Fedora release 35 (Thirty Five)

[dberry@t580 ~]$ LINES=10 top -b -w
top - 15:02:52 up 10 days,  5:41,  1 user,  load average: 2.41, 2.31, 2.58
Tasks: 402 total,   3 running, 399 sleeping,   0 stopped,   0 zombie
%Cpu(s): 19.4 us,  3.6 sy,  0.0 ni, 76.3 id,  0.0 wa,  0.7 hi,  0.0 si,  0.0 st
MiB Mem :  31937.7 total,   4147.8 free,  20284.9 used,   7505.0 buff/cache
MiB Swap:  24264.0 total,  19053.3 free,   5210.7 used.   6493.0 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
1554797 dberry    20   0 2894292 171920 115948 R  70.6   0.5   3298:49 Isolated Web Co
2266557 dberry    20   0 9359904 329760 114644 R  41.2   1.0   1:58.88 Isolated Web Co
1553004 dberry    20   0   12.0g   1.7g 649416 S  23.5   5.3 734:33.03 firefox

top - 15:02:55 up 10 days,  5:42,  1 user,  load average: 2.94, 2.42, 2.62
Tasks: 402 total,   4 running, 398 sleeping,   0 stopped,   0 zombie
%Cpu(s): 17.4 us,  1.6 sy,  0.0 ni, 80.3 id,  0.0 wa,  0.5 hi,  0.2 si,  0.0 st
MiB Mem :  31937.7 total,   4086.7 free,  20338.8 used,   7512.2 buff/cache
MiB Swap:  24264.0 total,  19053.3 free,   5210.7 used.   6431.9 avail Mem 

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
1554797 dberry    20   0 2894292 171920 115948 S  72.1   0.5   3298:51 Isolated Web Co
1553601 dberry    20   0 6184552   3.2g 133128 R  20.3  10.3   1487:35 Isolated Web Co
1553004 dberry    20   0   12.0g   1.7g 649416 S  18.6   5.3 734:33.59 firefox^C

Version-Release number of selected component (if applicable):
[root@el7a ~]# which top
/usr/bin/top
[root@el7a ~]# rpm -qf /usr/bin/top
procps-ng-3.3.10-28.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. log in to RHEL 7
2. LINES=10 top -b -w
3.

Actual results:
Shows all lines

Expected results:
Should show 10 lines

Additional info:
This is the latest version.

[root@el7a ~]# yum update
[root@el7a ~]# rpm -qf /usr/bin/top
procps-ng-3.3.10-28.el7.x86_64

Comment 5 RHEL Program Management 2023-08-15 07:28:27 UTC
After evaluating this issue, there are no plans to address it further or fix it in an upcoming release.  Therefore, it is being closed.  If plans change such that this issue will be fixed in an upcoming release, then the bug can be reopened.