[fpc-pascal] How to get info about CPU and Memory usage?

Ludo Brands ludo.brands at free.fr
Wed Feb 27 17:47:34 CET 2013


On 02/27/2013 05:25 PM, Krzysztof wrote:
> Hi,
> 
> I need system info such CPU (by PID), memory usage (by PID), free memory
> etc. Target platform: Linux.
> Linux have command line tools like ps, top, memstat, but I'm just
> wondering if Free Pascal has wrappers for these commands. If not, then I
> just get these information by execution external process.
> 

On newer linux kernels, instead of running external processes you can
better read and parse /proc/pid/stat (replace pid with the PID). If you
need per thread info you can read /proc/pid/task/tid/stat. These are
single line pseudo files with space separated values. Much easier than
parsing the free format output from ps, top, etc.
http://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html

Ludo




More information about the fpc-pascal mailing list