Lecture12 - CSCE 313 Introduction to Computer Systems...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: CSCE 313 Introduction to Computer Systems Instructor: Dr. Ronnie Ward Based on material from Dr. Riccardo Bettati POSIX Inter-Process Communication (IPC) Message Queues Shared Memory Semaphore Sets Accessing IPC resources from shell Reading: R&R, Ch 15 4/11/2010 POSIX IPC: Overview primitive POSIX function description message queues msgget msgctl msgsnd/msgrcv create or access control send/receive message Semaphore sets semget semctl semop create or access control wait or post operation shared memory shmget shmctl shmat/shmdt create and init or access control attach to / detach from process xxGET: Its all about Naming! Condition variables, mutex locks: Based on a memory variable concept. Does not work across memory spaces!! Pipes Uses file descriptors Works across memory spaces. Relies on inheritance of file descriptors -> does not work for unrelated processes. Named Pipes Uses file system as name space for pipe. Works for unrelated processes. Carry the overhead of the file system. IPC Objects Use system-global integer keys to refer to objects. POSIX Shared Memory A range of addresses created by the IPC facility for one process Other processes can attach the same shared memory segment into their own address space. Applications use this memory just as if it had been allocated by malloc When one application writes to shared memory in this range, the change is immediately available to any other process that has access to the same shared memory Shared memory doesnt provide any synchronization facilities. It is up to the programmer to synchronize access. POSIX Shared Memory #include <sys/shm.h> int shmget (key_t key, size_t size, int shmflg); shared-memory segment created by shmget address space of calling process P1 system memory void * shmat (int shmid, const void *shmaddr, int shmflg); address space of calling process P2 shared-memory segment mapped by shmat shared-memory segment mapped by shmat Ok, we have created a shared-memory segment. Now what? POSIX Shared Memory: shmget() this function is used to create a shared memory segment #include <sys/shm.h> int shmget (key_t key, size_t size, int shmflg); a programmer supplied key returns a shared memory identifier or -1 the amount of memory required, in bytes permission bits and IPC_CREAT ftok() ftok - generate an IPC key The ftok() function returns a key based on path and id that is usable in subsequent calls to msgget() , semget(), and shmget(). The application should ensure that the path argument is the pathname of an existing file that the process is able to stat(). Upon successful completion, ftok() returns a key. Otherwise, ftok() Upon successful completion, ftok() returns a key....
View Full Document

This note was uploaded on 02/14/2012 for the course CSCE 313 taught by Professor Gu during the Spring '11 term at Texas A&M.

Page1 / 43

Lecture12 - CSCE 313 Introduction to Computer Systems...

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

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