Limit the output of the TOP command to a specific process name

后端 未结 17 2505
臣服心动
臣服心动 2020-12-12 09:48

If you call the top command, you get all the running processes. But how can I limit the output only to a certain process name like \"java\"?

I\'ve

17条回答
  •  囚心锁ツ
    2020-12-12 10:21

    Using the approach mentioned in the answer by Rick Byers:

    top -p `pgrep java | paste -sd "," -`
    

    but I had more than 20 processes running so following command can be helpful for someone who encounter a similar situation.

    top -p `pgrep java | head -n 20 | paste -sd "," -`
    

    pgrep gets the list of processes with given name - java in this case. head is used to get first 20 pids because top cannot handle more than 20 pids when using -p argument. Finally paste joins the list of pids with ','.

    You can control the process name you are looking for in the above command and the number of processes with that name you are interested to watch. You can ignore the head -n 20 part if the number of your processes with the given name is less than 20.

提交回复
热议问题