Monitor specific process (ie apache) using Top

top -p `pidof apache2 | awk '{gsub(/[ ]/,",");print}'`
Show only specific process id's using Top
Sample Output
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
13130 www-data  20   0 31452 4536 1128 S    0  0.2   0:00.00 apache2            
12763 www-data  20   0 31596 4800 1220 S    0  0.2   0:00.00 apache2            
12762 www-data  20   0 31596 4800 1216 S    0  0.2   0:00.00 apache2            
12527 www-data  20   0 31596 4652 1220 S    0  0.2   0:00.01 apache2            
10760 www-data  20   0 31596 4940 1284 S    0  0.2   0:00.02 apache2  

0
By: hbalagtas
2011-07-28 20:13:36

These Might Interest You

  • In certain cases you mighy need to monitor the server load caused by certain process. For example HTTP, while stress testing apache using ab (apache benchmark) you may want to monitor the server status,load, # of spawned HTTP processes, # of established connections, # of connections in close wait state, apache memory footprint etc. Show Sample Output


    2
    watch -n1 "uptime && ps auxw|grep http|grep -v grep | grep -v watch|wc -l && netstat -ntup|grep :80 |grep ESTABLISHED|wc -l && netstat -ntup|grep :80|grep WAIT|wc -l && free -mo && ps -ylC httpd --sort:rss|tail -3|awk '{print \$8}'"
    rockon · 2012-06-06 12:12:10 1
  • This command allows you to find the effective uid and gid of the Apache process regardless of process name (which can be apache2 or httpd depending on distro).


    -1
    ps -o euid,egid --ppid `netstat --inet --inet6 -pln|awk '/:80 / { split($7,tmp, "/"); print tmp[1]; }'`|sort |uniq|grep -v EUID
    chx · 2010-11-18 21:22:29 0
  • Simply add this to whatever apache startup script you have, or if you are on a MAC, create a new automator application. This will show a pretty growl notification whenever theres a new Apache error log entry. Useful for local development


    0
    /usr/bin/tail -fn0 /path/to/apache_error.log | while read line; do /usr/local/bin/growlnotify --title "Apache Notice" --message "$line"; done &
    jhyland87 · 2013-01-22 05:25:41 0
  • This version also attaches to new processes forked by the parent apache process. That way you can trace all current and *future* apache processes.


    1
    ps auxw | grep sbin/apache | awk '{print"-p " $2}' | xargs strace -f
    msealand · 2013-02-19 19:14:57 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: