2

shm_open returns an fd associated with a "shared memory object". And normally, this object is then mapped into virtual memory (with mmap) to access as a memory-mapped file.

However, is it safe to access the shared memory object through its fd (as if it were a normal file)? And by "safe", I mean guaranteed by POSIX to have well-defined behavior?

The reason I'm asking is that I'm working with a third-party interface that will only accept an fd (instead of a memory address) for writing a fixed number of bytes.

4

1 回答 1

4

抱歉不行。 POSIX 说

如果fildes引用共享内存对象,则 write()函数的结果是未指定的。

..和同样的read()

不过,它确实可以在 Linux 上工作,其中共享内存对象是由文件系统支持的tmpfs文件。

于 2013-05-12T00:42:39.630 回答