Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Created February 14, 2014 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sirupsen/9001258 to your computer and use it in GitHub Desktop.
Save sirupsen/9001258 to your computer and use it in GitHub Desktop.
Virtual memory to physical memory.
$ ps -o rss,command | grep ./omg | grep -v grep
488 ./omg
$ ps -o rss,command | grep ./omg | grep -v grep
10268 ./omg
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
int main() {
int* lol = malloc(sizeof(int) * 10000000);
sleep(10);
printf("Touching memory pages..\n");
for (size_t i = 1; i < 10000000; i += getpagesize())
lol[i] = 82;
printf("Done touching memory pages..\n");
sleep(10);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment