p If .Dv O_CREAT is specified, then a new shared memory object named .Fa name will be created if it does not exist. In this case, the shared memory object is created with mode .Fa mode subject to the process' umask value. If both the .Dv O_CREAT and .Dv O_EXCL flags are specified and a shared memory object named .Fa path already exists, then .Fn shm_open will fail with .Er EEXIST .
p Newly created objects start off with a size of zero. If an existing shared memory object is opened with .Dv O_RDWR and the .Dv O_TRUNC flag is specified, then the shared memory object will be truncated to a size of zero. The size of the object can be adjusted via .Xr ftruncate 2 and queried via .Xr fstat 2 .
p The new descriptor is set to close during .Xr execve 2 system calls; see .Xr close 2 and .Xr fcntl 2 .
p The .Fn shm_unlink system call removes a shared memory object named .Fa path . .Sh RETURN VALUES If successful, .Fn shm_open returns a non-negative integer, and .Fn shm_unlink returns zero. Both functions return -1 on failure, and set .Va errno to indicate the error. .Sh COMPATIBILITY The .Fa path argument does not necessarily represent a pathname (although it does in most other implementations). Two processes opening the same .Fa path are guaranteed to access the same shared memory object if and only if .Fa path begins with a slash
q Ql / character.
p Only the .Dv O_RDONLY , .Dv O_RDWR , .Dv O_CREAT , .Dv O_EXCL , and .Dv O_TRUNC flags may be used in portable programs.
p The result of using .Xr open 2 , .Xr read 2 , or .Xr write 2 on a shared memory object, or on the descriptor returned by .Fn shm_open , is undefined. It is also undefined whether the shared memory object itself, or its contents, persist across reboots. .Sh ERRORS The following errors are defined for .Fn shm_open : l -tag -width Er t Bq Er EACCES The required permissions (for reading or reading and writing) are denied. t Bq Er EEXIST .Dv O_CREAT and .Dv O_EXCL are specified and the named shared memory object does exist. t Bq Er EFAULT The .Fa path argument points outside the process' allocated address space. t Bq Er EINVAL A flag other than .Dv O_RDONLY , .Dv O_RDWR , .Dv O_CREAT , .Dv O_EXCL , or .Dv O_TRUNC was included in .Fa flags ; or the .Fa path does not begin with a slash
q Ql / character. t Bq Er EMFILE The process has already reached its limit for open file descriptors. t Bq Er ENAMETOOLONG The entire pathname exceeded rq Dv PATH_MAX characters. t Bq Er ENFILE The system file table is full. t Bq Er ENOENT .Dv O_CREAT is specified and the named shared memory object does not exist. t Bq Er ENOTSUP Not supported, most likely due to missing or incorrect
p The following errors are defined for .Fn shm_unlink : l -tag -width Er t Bq Er EACCES The required permissions are denied. .Fn shm_unlink requires write permission to the shared memory object. t Bq Er EFAULT The .Fa path argument points outside the process' allocated address space. t Bq Er ENAMETOOLONG The entire pathname exceeded rq Dv PATH_MAX characters. t Bq Er ENOENT The named shared memory object does not exist. .El .Sh SEE ALSO .Xr close 2 , .Xr fstat 2 , .Xr ftruncate 2 , .Xr mmap 2 , .Xr munmap 2 .Sh STANDARDS The .Fn shm_open and .Fn shm_unlink functions are expected to conform to .St -p1003.1b-93 . .Sh HISTORY These functions first appeared in .Nx 7.0 .