0% found this document useful (0 votes)
13 views9 pages

Processes 3 Part 2

Uploaded by

f20212909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views9 pages

Processes 3 Part 2

Uploaded by

f20212909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

OPERATING SYSTEMS (CS F372)

Processes
Barsha Mitra
BITS Pilani CSIS Dept., BITS Pilani, Hyderabad Campus
Hyderabad Campus
Interprocess Communication
message passing shared memory

BITS Pilani, Hyderabad Campus


Producer-Consumer Problem

BITS Pilani, Hyderabad Campus


IPC – Shared Memory
 area of memory shared among cooperating processes
 create shared memory
 attach to shared memory
 shared memory region resides in address space of creating process
 faster than message passing
 system calls are required to establish shared memory region
 synchronization

BITS Pilani, Hyderabad Campus


shmget()
❖ Used to obtain the identifier of an existing shared memory
segment, or create a new one.
❖ int shmget(key_t key, size_t size, int shmflg);
❖ 3 parameters:
◆ key – unique value which the segment is associated with
◆ size – size of the shared memory segment
◆ shmflg – specify the read/write permissions along with
flags such as IPC_CREAT (if any)
❖ If successful, a valid shared memory identifier is returned, else -1 is
returned.

BITS Pilani, Hyderabad Campus


shmat()
❖ Used to attach a shared memory segment with the address space
of the calling process.
❖ void* shmat(int shmid, const void* shmaddr, int shmflg);
❖ 3 parameters:
◆ shmid – identifier for the shared memory segment
◆ shmaddr – address where the segment will be attached at
◆ shmflg – specify the read/write permissions for the calling
process.
❖ If successful, a void pointer to the segment’s start address is
returned, else (void*) -1 is returned.

BITS Pilani, Hyderabad Campus


shmdt()
❖ Used to detach a shared memory segment from the address space
of the calling process.
❖ int shmdt(const void* shmaddr);
❖ 1 parameter:
◆ shmaddr – address where the shared memory segment is
currently located at.
❖ If successful, the shared memory segment is detached from the
calling process and 0 is returned, else -1 is returned.

BITS Pilani, Hyderabad Campus


shmctl()
❖ Performs certain control operations on a shared memory segment.
❖ int shmctl(int shmid, int cmd, struct shmid_ds* buf);
❖ 3 parameters:
◆ Kernel
shmid – identifier
maintains for the
a special shared
internal datamemory
structure segment.
for each shared
cmd – specifies
◆ memory segment whichcontrolexists
operations to addressing
within its be performed onThis
space. the
segment,
structure such
is of typeasshmid_ds,
IPC_RMID and isto deleteinthe
defined segment.
sys/shm.h
◆ buf – pointer to a shmid_ds data structure as defined in the
sys/shm.h header file. Used in certain control operations.
❖ If successful, the specified control operation is performed on the
shared memory segment and 0 is returned, else -1 is returned.

BITS Pilani, Hyderabad Campus


Thank You

BITS Pilani, Hyderabad Campus

You might also like