by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :)by MathLes and ClintCode AYYILDIZ TEAM :) Computer Engineering Tips - Computer Engineering news and articles - Shared Memory Computer Engineering Tips - Computer Engineering news and articles - Shared Memory
  Home arrow Operating Systems arrow Fundamentals arrow Shared Memory
Computer Engineering Tips - Computer Engineering news and articles | _DATE_FORMAT_LC
 
 
Main Menu
Home
News
Algorithms
Artificial Intelligence
Bioinformatics
Computer Graphics
Computer Networks
Computer Organization
Computer Security
Data Mining
Data Structures
Database Systems
Distributed Computing
Internet
Operating Systems
Parallel Computing
Programming Languages
Publications
Robotics
Software Engineering
Other Articles


Partners

All Partners

 
 
 
Shared Memory _CMN_EMAIL
_USER_RATING: / 0
_VOTE_POOR_VOTE_BEST 

Shared memory is one of the most important Interprocess Communication methods being used these days. Access to the same memory and also getting the returning pointers to the same memory for two or more processes can be made possible by Shared memory, while all the other processes see the modification.

Shared memory is the fastest form of Interprocess Communication because all processes share the same piece of memory. Access to this shared memory is as fast as accessing a process’s non-shared memory and it does not require a system call or entry to the kernel. Copying of unnecessary data is also avoided.

Provision of your own synchronization must be there since the synchronization of accesses to shared memory is not taken care of by the kernel. For eg, a process should not read from the memory until data is written there and two processes must not write to the same memory location at the same time. A common strategy to avoid these race conditions is to use semaphores.

The memory model

To use a shared memory segment, one process must allocate the segment. Than each process desiring to access the segment must attach the segment. After finishing its use of the segment, each process detaches the segment. At some point, one process must de-allocate the segment.

Allocation

A process allocates a shared memory segment using shmget (“Shared Memory Get”). Its first parameter is an integer key that specifies which segment to create. Same shared segment can be accessed by unrelated processes specifying the same key value. But there can be conflict since same fixed key may also be chosen by other proceses. Using the special constant IPC_PRIVATE as the key value guarantees that a brand new memory segment is created.

Its second parameter specifies the number of bytes in the segment. Because segments are allocated using pages, the number of actually allocated bytes is rounded up to an integral multiple of the page size.

The third parameter is the bitwise or of the flag values that specify options to shmget. The flag values include these:

  • IPC_CREAT
  • This flag indicates that a new segment should be created. This permits creating a new segment while specifying a key value.

  • IPC_EXCL
  • This flag which is always used with IPC_CREAT, causes shmget to fail if a segment key is specified that already exists. Therefore, it arranges for the calling process to have an “exclusive” segment. If this flag is not given and the key of an existing segment is used, shmget returns the existing segment instead of creating a new one. For example, following invocation of shmget creates a new shared memory segment that has read and writes permissions to the owner but not to other users.

int segment_id = shmget(shm_key,getpagesize(),IPC_CREAT | S_IRUSR | S_TWUSR);

If the call succeeds, shmget returns a segment identifier. If the shared segment already exists, the access permissions are verified and a check is made to ensure that the segment is not marked for destruction.

Attachment and Detachment

To make the shared memory segment available, a process must use shmat, “Shared Memory Attach”. Pass it the shared memory segment identifier SHMID returned by shmget. The second argument is a pointer that specifies where in your process’s address space you want to map the Shared Memory; if you specify NULL, Linux will choose an available address.If the call succeeds, it returns the address of the attached shared segment.

Controlling and De-allocating Shared Memory

The shmctl(“Shared Memory Control”) call returns information about a shared segment and can modify it. To remove a segment, pass IPC_RMID as the second argument, and pass NULL as the third argument. The segment is removed when the last process that has attached it finally detaches it. Each Shared Memory should be explicitly de-allocated using shmctl when you are finished with it.

 
 Sponsored Links

_USER_RATING: / 0
_VOTE_POOR_VOTE_BEST 
_ITEM_PREVIOUS   _ITEM_NEXT
 
       
         
     
 
Advertisement
 
   

Copyright 2005 - 2006 Science Tips Team. All rights reserved.

Nanotechnology Development Blog