Linux Top team with over 20 teams

I want to use top to track numerous processes by process name. I already know about doing $ top -p $(pgrep -d ',' <pattern>) , but top limits me to only 20 pids. Is there a way to allow more than 20 pids?

Do I need to use a combination of ps and watch to get similar results?

+2
linux bash top-command
Aug 14 '14 at 19:19
source share
2 answers

From top/top.c :

 if (Monpidsidx >= MONPIDMAX) error_exit(fmtmk(N_fmt(LIMIT_exceed_fmt), MONPIDMAX)); 

(where LIMIT_exceed_fmt is the error message you receive).

And in top/top.h :

 #define MONPIDMAX 20 

I changed this number to 80, and it seems to be working fine. I do not know why this rigidly defined limit is so low.

So, if you manually compile procps-ng , you can do it. You do not need to replace the top of the system (or use root privileges), you can just put it in your homedir.

Another workaround would be to use tmux or screen and multiple instances of top .

Another possible solution would be to use ps with a loop, i.e.

 #!/bin/sh while :; do clear ps $* sleep 1 done 

Call it like: ./psloop.sh 42 666

For more information, you can add additional flags in ps . Also keep in mind that this is less efficient since it will call 3 binary files every second.

+5
Aug 14 '14 at 19:30
source share

Wrap with a clock. Tested with Ubuntu 11.04, Ubuntu 14.04, RHEL5, RHEL6 and RHEL7

Syntax: script.sh pid [ pid ...] # space allocated




Example: script.sh $(pgrep -d ' ' <pattern>)


 #! / bin / bash

 i = 10 # ~ interval in seconds

 format ()
 {
   a = "$ 1 $ 2 $ 3 $ 4 $ 5 $ 6 $ 7 $ 8 $ 9 $ {10} $ {11} $ {12}"
   a = "$ a $ {13} $ {14} $ {15} $ {16} $ {17} $ {18} $ {19} $ {20}"
   a = "$ {a %% * ()}";  a = "$ {a // /,}"
 }

 main ()
 {
   format $ @
   top -b -n 1 -p $ a
   [$ # -gt 20] && shift 20 ||  shift $ #

   until [$ # -eq 0];  do
     format $ @
     top -b -n 1 -p $ a |  sed '1, / PID / d; / ^ $ / d'
     [$ # -gt 20] && shift 20 ||  shift $ #
   done
 }

 if ["$ 1" == "watch"];  then
   shift
   shopt -s extglob
   main $ @
 else
   watch -t -n $ i "$ 0 watch $ @"
 fi
+2
Aug 14 '14 at 23:16
source share



All Articles