Skip to content

Instantly share code, notes, and snippets.

@sitano
Created June 10, 2021 14:23
Show Gist options
  • Save sitano/a20bbc96d8cdf62f7d2d3896bcbb78ca to your computer and use it in GitHub Desktop.
Save sitano/a20bbc96d8cdf62f7d2d3896bcbb78ca to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
int main(void)
{
int x,status;
int *arr1 = calloc(500000000, 1);
x = fork();
if(x>0){
wait(&status);
} else {
for (size_t i = 0; i < 500000000; i += 4096) {
arr1[i] ++;
for (size_t j = 0; j < 100000; j ++) {
sched_yield();
}
}
exit(0);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment