Posts

Showing posts with the label out-of-memory

Linux- Out of Memory

Image
Clash Royale CLAN TAG #URR8PPP Linux- Out of Memory I was trying to see the working of oom_kill by invoking manually. I allocated memory dynamically and tried to use them infinitely with while loop at first and then with the for loop to test out of memory. But in the first case where I used the while loop it threw segmentation fault without swap and became unresponsive with swap whereas with the for loop out of memory (oom_kill) was invoked. Sample codes of both: First case: while: int main (void) { char* p; while (1) { p=malloc(1<<20); memset (p, 0, (1<<20)); } } Second case : for : int main (void) { int i, n = 0; char *pp[N]; for (n = 0; n < N; n++) { pp[n] = malloc(1<<20); if (pp[n] == NULL) break; } printf("malloc failure after %d MiBn", n); for (i = 0; i < n; i++) { ...