mmap start failing after n runs

时间:2019-04-13 15:32:45

标签: c segmentation-fault mmap

I have a problem with mmap. It worked fine for some time, but after 7 or 8 runs it started to fail on 2 instances of virtualized Linux. I really don't how to fix it.

int shm_m = shm_open("/sharedMemory", O_CREAT | O_EXCL | O_RDWR, 0644);
ftruncate(shm_m, sizeof(int) * 3);
int *shared_ints;
if ((shared_ints = mmap(NULL, sizeof(int) * 3, PROT_READ | PROT_WRITE, 
     MAP_SHARED, shm_m, 0)) == (void *)-1)
{
    printf("Memory mapping failed\n");
    return 1;
}
shared_ints[0] = 1;
// Molo serfs
shared_ints[1] = 0;
// Molo hackers
shared_ints[2] = 0;

0 个答案:

没有答案