Your code does share memory, but both of your processes will get different address areas. You want to have the same region, so the value of addr will be the same. In this case, you can create objects in this memory, use internal pointers, and your objects will be real and visible in both processes.
There are two ways you can do this.
1) make fork () to create another process
2) ask mmap to allocate memory at the special address MAP_FIXED .
For the second number your code will look:
fd = shm_open( "/bolts", O_RDWR | O_CREAT, 0777 ); if( fd == -1 ) { fprintf( stderr, "Open failed:%s\n", strerror( errno ) ); return EXIT_FAILURE; } if( ftruncate( fd, sizeof( *addr ) ) == -1 ) { fprintf( stderr, "ftruncate: %s\n", strerror( errno ) ); return EXIT_FAILURE; }

source share