0% found this document useful (0 votes)
13 views

Shared Memory

shmget() is used to get a shared memory identifier. The key argument is used to identify the shared memory segment and should be unique, often generated with getuid(). The size argument specifies the number of bytes to allocate. The shmflag argument is used to specify creation permissions if IPC_CREAT is used. The shmid returned by shmget() is passed to shmat() to attach to the shared memory. The 2nd and 3rd arguments to shmat() can specify a specific address but usually are left as 0. Shared memory segments are represented by a shmid_ds data structure containing metadata like size, permissions, and pointers to the shared memory pages. Process virtual memory areas

Uploaded by

Brajendra Mohan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Shared Memory

shmget() is used to get a shared memory identifier. The key argument is used to identify the shared memory segment and should be unique, often generated with getuid(). The size argument specifies the number of bytes to allocate. The shmflag argument is used to specify creation permissions if IPC_CREAT is used. The shmid returned by shmget() is passed to shmat() to attach to the shared memory. The 2nd and 3rd arguments to shmat() can specify a specific address but usually are left as 0. Shared memory segments are represented by a shmid_ds data structure containing metadata like size, permissions, and pointers to the shared memory pages. Process virtual memory areas

Uploaded by

Brajendra Mohan
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 4

shmget(): Argument Values

key
same as before; we use getuid() to make it unique

size
number of bytes to allocate

shmflag
Creating: IPC_CREAT and permissions 0 for accessing only

Notes on shmat() arguments


shmid

is as before 2nd and 3rd arguments can be used to attach to a specific address within shmem, but it is an absolute address, requiring knowledge of the address of the shared memory segment Almost always, 2nd and 3rd arguments are 0

Shared Memory Data Structure


/* One shmid data structure for each shared memory segment in the system. */ struct shmid_ds { struct ipc_perm shm_perm; /* operation perms */ int shm_segsz; /* size of segment (bytes) */ time_t shm_atime; /* last attach time */ time_t shm_dtime; /* last detach time */ time_t shm_ctime; /* last change time */ unsigned short shm_cpid; /* pid of creator */ unsigned short shm_lpid; /* pid of last operator */ short shm_nattch; /* no. of current attaches */ /* the following are private */ unsigned short shm_npages; /* size of segment (pages) */ unsigned long *shm_pages; /* array of ptrs to frames -> SHMMAX */ struct vm_area_struct *attaches; /* descriptors for attaches */ };

Virtual Memory Area Structure


vm_area_struct defines a memory VMM memory area. There is one of these per VM-area/task. A VM area is any part of the process virtual memory space that has a special rule for the page-fault handlers (ie a shared library, the executable area etc).

struct vm_area_struct { struct mm_struct * vm_mm; unsigned long vm_start; unsigned long vm_end; struct vm_area_struct *vm_next; pgprot_t vm_page_prot; unsigned long vm_flags; rb_node_t vm_rb; struct vm_area_struct *vm_next_share; struct vm_area_struct **vm_pprev_share; struct vm_operations_struct * vm_ops; unsigned long vm_pgoff; struct file * vm_file; unsigned long vm_raend; void * vm_private_data; };

You might also like