Shared Memory - Working Note

The most simple working example

#define _XOPEN_SOURCE 700

#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>

int main(){
    int fd; // shared memory working segment
    int * sp; // segment pointer
    fd = shm_open("myshm", O_RDWR | O_CREAT, 0600);
    ftruncate(fd, sizeof(int));
    sp = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    *sp = 10;
    munmap(sp, sizeof(int));
    shm_unlink("myshm");
}

An improvement