#Include : SHM - RDONLY, Which Makes The Attached Memory Read-Only
#Include : SHM - RDONLY, Which Makes The Attached Memory Read-Only
#include <sys/shm.h>
The program provides key which effectively names the shared memory segment. Special key
(IPC_PRIVATE) creates shared memory private to the process.
Shmflg- Nine permission flags that are used in the same way as mode flag for creating files.
If the shared memory is successfully created, shmget returns a nonnegative integer, the shared
memory identifier. On failure, it returns –1.
2. When you first create a shared memory segment, it’s not accessible by any process. To
enable access to the shared memory, you must attach it to the address space of a process.
The first parameter, shm_id, is the shared memory identifier returned from shmget.
The second parameter, shm_addr, is the address at which the shared memory is to be attached to the
current process. This should almost always be a null pointer, which allows the system to choose the
address at which the memory appears.
The third parameter, shmflg, is a set of bitwise flags. The two possible values are SHM_RND, which,
in conjunction with shm_addr, controls the address at which the shared memory is attached, and
SHM_RDONLY, which makes the attached memory read-only.
If the shmat call is successful, it returns a pointer to the first byte of shared memory. On failure –1 is
returned.
3. The shmdt function detaches the shared memory from the current process. It takes a pointer
to the address returned by shmat. On success, it returns 0, on error –1. Note that detaching
the shared memory doesn’t delete it; it just makes that memory unavailable to the current
process.
The second parameter, command, is the action to take. It can take three values: IPC_STAT, IPC_SET,
IPC_RMID.
IPC_STAT: Sets the data in the shmid_ds structure to reflect the values associated with the shared
memory.
IPC_SET: Sets the values associated with the shared memory to those provided in the shmid_ds data
structure, if the process has permission to do so.