Shared Memory  Creating a Shared Memory Segment Allocated in byte amounts  Shared Memory Operations Create Attach Detach  Shared Memory Control Remove.

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP5570 – Advanced Unix Programming IPC mechanisms Pipes Sockets System V IPC –Message Queues –Semaphores –Shared Memory.
Advertisements

1 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania Fall 2003 Lecture Note 2.6: Message-Based Communication.
Unix IPC and Synchronization. Pipes and FIFOs Pipe: a circular buffer of fixed size written by one process and read by another int pipe(int fildes[2])
XSI IPC Message Queues Semaphores Shared Memory. XSI IPC Each XSI IPC structure has two ways to identify it An internal (within the Kernel) non negative.
Shared memory. Process A Process B Physical Memory Virtual address space A Virtual address space B Share Instruction memory Data Instruction memory Data.
Inter-process communication (IPC) using Shared Memory & Named Pipes CSE 5520/4520 Wireless Networks.
System V IPC (InterProcess Communication) Messages Queue, Shared Memory, and Semaphores.
Introduction to Memory Management 黃偉修 Linux Kernel.
1 Tuesday, June 27, 2006 "If the 8086 architects had designed a car, they would have produced one with legs, to be compatible with the horse." - Anonymous.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
UNIX IPC CSE 121 Spring 2003 Keith Marzullo. CSE 121 Spring 2003Review of Concurrency2 Creating a UNIX process A process is created by making an exact.
NCHU System & Network Lab Lab 10 Message Queue and Shared Memory.
Unix IPC Unix has three major IPC constructs to facilitate interaction between processes: Message Queues (this PowerPoint document) permit exchange of.
Memory Mapping Sarah Diesburg COP5641.
Inter-Process Communication: Message Passing
Operating Systems, 132 Practical Session 9, Memory 1.
CS162B: Semaphores (and Shared Memory) Jacob T. Chan.
Tru64 UNIX Internals IIProcess Address Space1 - 1 Representing a Process’s Address Space Chapter One.
System Config IPC Iris Zhu
1 Chapter 6 Interprocess Communications. 2 Contents u Introduction u Universal IPC Facilities u System V IPC.
Lecture 6 Introduction to Distributed Programming System V IPC: Message Queues, Shared Memory, Semaphores.
Inter-Process Communication Mechanisms CSE331 Operating Systems Design.
Thread Synchronization with Semaphores
The Third Assignment COSC 4330/6310 Spring Implementing delays To be able to test the semaphores, we must run the program in real time To be able.
S -1 Shared Memory. S -2 Motivation Shared memory allows two or more processes to share a given region of memory -- this is the fastest form of IPC because.
System V IPC Provides three mechanisms for InterProcess Communication (IPC) : Messages : exchange messages with any process or server. Semaphores : allow.
TANNENBAUM SECTION 2.3 INTERPROCESS COMMUNICATION2 OPERATING SYSTEMS.
Lecture 7 Introduction to Distributed Programming System V IPC: Message Queues, Shared Memory, Semaphores.
Florida State UniversityCOP5570 – Advanced Unix Programming Today’s topics System V Interprocess communication (IPC) mechanisms –Message Queues –Semaphores.
1 Semaphores Chapter 7 from Inter-process Communications in Linux: The Nooks & Crannies by John Shapley Gray Publisher: Prentice Hall Pub Date: January.
1 Shared Memory. 2  Introduction  Creating a Shared Memory Segment  Shared Memory Control  Shared Memory Operations  Using a File as Shared Memory.
Semaphores Creating and Accessing Semaphore Sets Semaphore Operations
Interprocess Communication Bosky Agarwal CS 518. Presentation Layout Introduction Pipes FIFOs System V IPC 1.Using pipes 2.Working of pipes 3.Pipe Data.
File descriptor table File descriptor (integer)File name 0stdin 1stdout 2stderr Use open(), read(), write() system calls to access files Think what happens.
UNIX IPC CSC345.
Inter Process Comunication in Linux by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Semaphores Chapter 7 from Inter-process Communications in Linux:
© 2006 RightNow Technologies, Inc. Synchronization September 15, 2006 These people do not actually work at RightNow.
Advanced UNIX IPC Facilities After Haviland, et al.’s book.
Slide 9-1 Copyright © 2004 Pearson Education, Inc. Inter process Communication Mechanisms  Allow arbitrary processes to exchange data and synchronize.
Interprocess Communication
IPC Message Queue. Data Structure msgque IP_NOUSED.
1 Structure of Processes Chapter 6 Process State and Transition Data Structure for Process Layout of System Memory THE DESIGN OF THE UNIX OPERATING SYSTEM.
Message Queues. Unix IPC Package ● Unix System V IPC package consists of three things – Messages – allows processes to send formatted data streams to.
Shared Memory Dr. Yingwu Zhu. Overview System V shared memory Let multiple processes attach a segment of physical memory to their virtual address spaces,
What is a Process ? A program in execution.
Why Kernel Works? kernel function gets dynamic memory in a fairly straightforward manner _get_free_pages( ) or alloc_pages( ) The simple approaches work.
Memory Management 백 일 우
Textbook: Advanced Programming in the UNIX Environment, 2 nd Edition, W. Richard Stevens and Stephen A. Rago 1 Chapter 15. Interprocess Communication System.
Operating Systems Inter-Process Communication Shared Memory & Semaphores Moti Geva
Linux/UNIX Programming APUE (Interprocess Communication)
Lecture 7 Introduction to Distributed Programming System V IPC:
Message queue Inter process communication primitive
Virtual Memory: Systems
Linux Interprocess Communication
Unix IPC Unix has three major IPC constructs to facilitate interaction between processes: Message Queues (this PowerPoint document) permit exchange of.
Shared Memory Dr. Yingwu Zhu.
Virtual Memory: Systems
Interprocess Communication and Synchronization using System V IPC
Message Queues.
Inter Process Communication
Unix programming Term: Unit-V I PPT Slides
Pentium III / Linux Memory System April 4, 2000
Virtual Memory.
Introduction to Distributed Programming System V IPC:
Virtual Memory: Systems CSCI 380: Operating Systems
| Website for Students | VTU -NOTES -Question Papers
Structure of Processes
Shared Memory Dr. Yingwu Zhu Feb, 2007.
Paging Adapted from: © Ed Lazowska, Hank Levy, Andrea And Remzi Arpaci-Dussea, Michael Swift.
Presentation transcript:

Shared Memory  Creating a Shared Memory Segment Allocated in byte amounts  Shared Memory Operations Create Attach Detach  Shared Memory Control Remove

shmget System Call Function  The shmget system call is used to create or access a shared memory segment. Include: Command: int shmget (key_t key, int size, int shmflg); Returns: Success: unique shared memory identifier. Failure: -1 ; Sets errno: Yes. Arguments: key_t key: key for creating or accessing shared memory int size: size in bytes of shared memory segment to create. Use 0 for accessing an existing segment. int shmflg: segment creation condition and access permission.

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

Shared Memory Limits Shared Memory Segment Defaults Value Maximum segment size 1,048,576 bytes Minimum segment size 1 byte System wide maximum number of segments 100 Maximum number of segments per process 6? that can be attached

shmat System Call Function:  used to attach (map) the referenced shared memory segment into the calling process’s data segment. The pointer returned is to the first byte of the segment Include: Command: void *shmat ( int shmid, void *shmaddr, int shmflg); Returns: Success:Reference to the data segment address of shared memory; Failure:-1; Sets errno:Yes. Arguments: int shmid: a valid shared memory identifier. void *shmaddr: allows the calling process some flexibility in assigning the location of the shared memory. int shmflg: access permissions and attachment conditions.

Notes on shmat() arguments  shmid is as before  2 nd and 3 rd 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, 2 nd and 3 rd arguments are 0

shmdt System Call Function shmdt is used to detach the calling process’s data segment from the shared memory segment. Include: Command: int shmdt (void * shmaddr); Returns: Success: 0; Failure: -1; Sets errno: Yes. Argument: void *shmaddr: a reference to an attached memory segment (the shared memory pointer).

shmctl call - Shared Memory Control Function: shmctl permits the user to perform a number of generalized control operations on an existing shared memory segment and on the system shared memory data structure. Include: Command: int shmctl(int shmid, int cmd, struct shmid_ds * buf); Return: Success: 0; Failure: -1; Sets errno: Yes. Arguments int shmid: a valid shared memory segment identifier. int cmd: the operation shmctl is t perform. struct shmid_ds * buf: a reference to the shmid_ds structure

Operations of shmctl()  IPC_STAT: Return the current value of the shmid_ds structure for the shared memory segment indicated by the shmid value.  IPC_SET: Modify a limited number of members in the permission structure found within the shmid_ds structure.  IPC_RMID: Remove the system data structure for the referenced shared memory identifier (shmid). Once all references to the shared memory segment are eliminated, the system will remove the actual shared memory segment.  SHM_LOCK: Lock, in memory, the shared memory segment referenced by the shmid argument. Superuser access required  SHM_UNLOCK: Unlock the shared memory segment referenced by the shmid argument. Superuser access required

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; };

ipcs & ipcrm Command * % ipcs -b (-b to display the maximum number of bytes ) T ID KEY MODE OWNER GROUP QBYTES Message Queues: q 50 0X67028a01 -Rrw-rw---- gray other 4096 Shared Memory facility not in system T ID KEY MODE OWNER GROUP NSEMS Semaphores: s 0 0X000187cf --ra-ra-ra- root root 2 s 1 0X000187ce --ra-ra-ra- root root 1