SharedMemory - Shared Memory Dr Yingwu Zhu Feb 2007 Overview Shared Memory An efficient means of process communication Creation shmget Access

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Shared Memory Dr. Yingwu Zhu Feb, 2007
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Overview: Shared Memory An efficient means of process communication Creation: shmget() Access control: shmctl() Attached to addr. space: shmat() Detached from addr. space : shmdt() #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h>
Background image of page 2
Accessing a share memory int shmget(key_t key, size_t size, int shmflg) - key: share mem. Identifier - size: number of bytes - shmflg: access permissions flags - return: shared mem. Segment ID
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Controlling a Shared Mem. Seg. int shmctl(int shmid, int cmd, struct shmid_ds *buf); cmd: SHM_LOCK(sup user), SHM_UNLOCK, IPC_STAT (read), IPC_SET(owner, creater, sup), IPC_RMID
Background image of page 4
Attaching a Shared Mem. Seg. void *shmat (int shmid, const void*shmaddr, int shmflg); Return a pointer to the head of the shared segment associated with shmid
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Detaching a Share Mem. Seg. int shmdt(const void* shmaddr);
Background image of page 6
Examples: server.c main() { char c; int shmid; key_t key; char *shm, *s; /* * We'll name our shared memory segment * "5678". */ key = 5678;
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/01/2011 for the course CSSE 250 taught by Professor Dr.yingwuzhu during the Spring '11 term at UH Clear Lake.

Page1 / 10

SharedMemory - Shared Memory Dr Yingwu Zhu Feb 2007 Overview Shared Memory An efficient means of process communication Creation shmget Access

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online