http://pagesperso-orange.fr/sebastien.godard/tutorial.html - important
What is the purpose of pidstat?
The pidstat command is used to monitor processes and threads currently being managed by the Linux kernel. It can also monitor the children of those processes and threads.
Can I use pidstat with nagios or other monitoring tool to log performance information for all the processes?
I do not know this yet. I am not sure if this is a wise thing to do neither. Also, can we log the output of top somehow?
What is the purpose of the -d command line option?
With its -d option, pidstat can report I/O statistics, providing that you have a recent Linux kernel (2.6.20+) with the option CONFIG_TASK_IO_ACCOUNTING compiled in. So imagine that your system is undergoing heavy I/O and you want to know which tasks are generating them. You could then enter the following command:
pidstat -d 2
What happen if we do not specify a PID?
When no PID's are explicitly selected on the command line, the pidstat command examines all the tasks managed by the system but displays only those whose statistics are varying during the interval of time. But you can also indicate which tasks you want to monitor. The following example reports CPU statistics for PID 8197 and all its threads:
pidstat -t -p 8197 1 3
How can we use pidstat to find memory leak?
pidstat -r 2
pidstat had a memory footprint (VSZ and RSS fields) that was constantly increasing as the time went by. I quickly found that I had forgotten to close a file descriptor in a function of my code and that was responsible for the memory leak…!