2. Now, run free, perhaps using some of the arguments that might be useful (e.g., -m, to display memory totals in megabytes). How much memory is in your system? How much is free? Do these numbers match your intuition?
siuwhat@siuwhat-PC:~/Desktop/HW-Lottery$ free -m total used free shared buff/cache available Mem: 1970 1305 123 44 541 461 Swap: 4095 70 4025
3. Next, create a little program that uses a certain amount of memory, called memory-user.c. This program should take one command-line argument: the number of megabytes of memory it will use. When run, it should allocate an array, and constantly stream through the array, touching each entry. The program should do this indefinitely, or, perhaps, for a certain amount of time also specified at the command line.
8. Finally, let’s run pmap on your your memory-user program, with different amounts of used memory. What do you see here? Does the output from pmap match your expectations?
#include <iostream> #include<unistd.h> using namespace std; int main(int argc, char *argv[]) { size_t mem=atoi(argv[1]); const size_t num=mem*1024*1024/sizeof(int); int array[num]; while(true){ for(int i=0;i<num;++i) {array[i]=i; cout<<getpid()<<" "<<i<<endl;} } return 0; }