The most straight forward way to use top is typing top in your command line. This will give a a quick view of the processes in the system. Those key strokes are useful in this mode:
- q, quit
- space or enter, refresh the view
- M, sort by %MEM column
- T, sort by TIME column
- P, sort by %CPU column
- m, toggle memory usage section display (less useful)
- t, toggle task/cpu section display (less useful)
top -b > /tmp/top.output
This will give you one snapshot. For multiple iterations, you can use -n # option. Also you can limit your output to certain processes by specifying process id. For example:
top -b -n 5 -p 12639, 6932 > /tmp/top.output
This will give you 5 iterations of usage of process 12639 and 6932
One last option in batch mode you may need is -u or -U which is the user id or name. For example:
top -b -n 2 -u alex
or
top -b -n 2 -u 1012
You can set up a cron job to run top periodically and process the output if your application doesn't have more sophisticated monitoring mechanism built in.
No comments:
Post a Comment