close() on shared memory in osx causes invalid argument error

时间:2016-02-12 19:55:32

标签: c macos shared-memory

The following code

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

int
main(int argc, char **argv)
{
    char *p;
    int shm_fd;
    int error;
    size_t len;
    if ((shm_fd = shm_open("/somename", O_CREAT | O_RDWR, 0666)) < 0) {
        perror("shm_open");
        exit(1);
    }
    error = close(shm_fd);
    if (error < 0) {
        perror("close");
    }
    return 0;
}

Works fine on fedora22 x86_64, freebsd 10.2 x86_64. But it fails on OSX 10.10 with

close: Invalid argument

What is wrong with the call on OSX?

0 个答案:

没有答案