Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to exclude some processes from being reported by top?

For example, I would like to exclude itself from its listing (ie, I don't want top to show in the process list).

I would also like to be able to exclude processes that do not belong to the user running top (except for root).

Is this possible? If so, how? If not, is there a similar tool that will do what I want (that does not involve running something like ps frequently).


I realize that you can monitor just a given user's processes by invoking with the -u or -U options, but that's not the same as monitoring only processes owned by the user running top.

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Top gets its information directly from the /proc filesystem which is "dummy" filesystem dynamically generated by the Linux kernel.

Therefore hiding specific processes (such as itself) is only possible if

  1. You write a kernel module that hijacks the /proc fs
  2. You modify the source code of top application (user level code)

If you want complete control over what is visible you should write a script/program yourself that reads /proc.

I suggest that you explore /proc a bit more. You might get away with a simple grep/cat/awk script that does what you want.

share|improve this answer
    
You can 'hide' processes in top if you can get the lookups in /proc to respond with EPERM. SELinux does this if you use certain specialist roles like 'user_u'. But I think what OP wants is a means to filter top. –  Matthew Ife May 11 '13 at 10:42
add comment

top | grep -v gives that to some extent. But the display will get overlapped as the top refreshes.

share|improve this answer
2  
Wrong. grep will run on one round of top output only. –  vonbrand May 11 '13 at 11:12
    
top -n1 (in Linux) or top -l1 (Mac OS X) will exit after sending just one iteration of output to STDOUT. –  200_success May 11 '13 at 15:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.