Skip to content

Instantly share code, notes, and snippets.

@dmikurube
Created January 16, 2014 04:22
Show Gist options
  • Save dmikurube/8449751 to your computer and use it in GitHub Desktop.
Save dmikurube/8449751 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#define A1 (1024 * 1024 * 200)
#define A2_PARENT (1024 * 1024 * 300)
#define A2_CHILD (1024 * 1024 * 500)
int main() {
char* a1;
char* a2;
pid_t pid;
a1 = (char *)malloc(A1);
for (int i = 0; i < A1; ++i) {
*(a1 + i) = 0xca;
}
pid = fork();
if (pid > 0) { // parent
int status;
a2 = (char *)malloc(A2_PARENT);
for (int i = 0; i < A2_PARENT; ++i) {
*(a2 + i) = 0xfe;
}
waitpid(pid, &status, 0);
} else if (pid == 0) { // child
a2 = (char *)malloc(A2_CHILD);
for (int i = 0; i < A2_CHILD; ++i) {
*(a2 + i) = 0xba;
}
sleep(6000);
}
return 0;
}
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
114584 24702 8.7 0.7 516168 512224 pts/9 S+ 13:15 0:01 ./fork_memory_usage
114584 24703 11.0 1.0 720968 716760 pts/9 S+ 13:15 0:01 ./fork_memory_usage
180242 179190 7 1 0 179247 0
129042 128056 86 1 0 128047 0
@dmikurube
Copy link
Author

Total RSS of them without double-counting is 1049071616 bytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment