René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Unix (Solaris?) tools: ps | ||
Here's a C++ program that should demonstrate the influence of allocating memory on some flags used in ps. The program, when run, repeadetly asks for amounts in kilo bytes to be allocated. These chunks can then be observed calling ps.
The first thing, however, When the program is run, is that it prints its process id (
PID ) which then can be used like so:
ps -p PID -o osz,vsz,rss,pmem
The meaning of the given flags is:
// Compile with: // CC demo_ps_o_vsz.cpp -o demo_ps_o_vsz #include <unistd.h> #include <iostream> int main() { unsigned int kbToAllocate; char* allocatedMemory; std::cout << std::endl << "My PID is: " << getpid() << std::endl; do { std::cout << std::endl << "Allocate Memory [kBytes] (0 ends programm): "; std::cin >> kbToAllocate; allocatedMemory = new char[kbToAllocate * 1024]; // Different behavior for rss if following block // commented out: for (unsigned int i=0; i<kbToAllocate; i++) { allocatedMemory[i*1024] = 0; } } while (kbToAllocate); } |