I wrote code on Mac OS X to use POSIX shared memory, as shown below:
#include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/types.h> int main() { int fileHandle = shm_open("TW_ShMem1",O_CREAT|O_RDWR, 0666); if(fileHandle==-1) { //error. } else { //Here, it is failing on Mac OS X if(-1==ftruncate(fileHandle, 8192)) { shm_unlink("TW_ShMem1"); fileHandle = -1; } else { return 0; } } return 1; }
ftruncate on Linux works without problems. On Mac OS X, it returns -1, and errno returns EINVAL (as shown in the debugger).
Why does he fail? What is missing here?
c linux shared-memory macos
doptimusprime
source share