// The program just illustrates the memory usage. // It creates an array of doubles of size 100 millions, // fills it with arbitrary numbers, and calculates // its sum in the infinite loop. Several such processes // running simultaneously exaust the physical memory // of computer and initiate swapping. // // To start the process, execute the command line // ./memtst ProcessName #include int main(int argc, char *argv[]) { printf("Number of command line arguments: %d\n", argc); for (int i = 0; i < argc; ++i) { printf("arg %d: %s\n", i, argv[i]); } const char *processName = "noname"; if (argc > 1) processName = argv[1]; int n = 100000000; // 100 millions double* a = new double[n]; for (int i = 0; i < n; ++i) a[i] = (double) i; while (true) { double sum = 0.; for (int i = 0; i < n; ++i) sum += a[i]; printf("Process %s: sum = %lf\n", processName, sum); } return 0; }