Created
January 16, 2014 04:22
-
-
Save dmikurube/8449751 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
180242 179190 7 1 0 179247 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129042 128056 86 1 0 128047 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Total RSS of them without double-counting is 1049071616 bytes.