Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

my_shm.h File Reference

Go to the source code of this file.

Defines

#define SHM_PERMISSION   0x000001C0
 Define default permissions for all newly created SHM. It should ne read just like file permissions: 0x1C0 = 111000000 in binary, that is 111 000 000. This gives all rights for the user and nothing for other users.

#define CREATE_SHM_OK   -1
 Return value for the function create_shared_memory_segment(). This means that the SHM has been successfully created.

#define CREATE_SHM_ALREADY_CREATED   -2
 Return value for the function create_shared_memory_segment(). This means that the SHM has already been created.

#define CREATE_SHM_ERROR   -3
 Return value for the function create_shared_memory_segment(). This means that an error occured while creating the shared memory segment.

#define GET_SHM_OK   -1
 Return value for the function get_shared_memory_segment_sys_id(). This means that the SHM system identifier has been looked up successfully.

#define GET_SHM_ALREADY_GET   -2
 Return value for the function get_shared_memory_segment_sys_id(). This means that the SHM system identifier jas already been looked up.

#define GET_SHM_ERROR   -3
 Return value for the function get_shared_memory_segment_sys_id(). This means that an error occured while getting the system's identifier.

#define SHM_HD

Functions

void change_shm_access_permission (int new_permission)
 Change the SHM's default permissions.

int create_shared_memory_segment (key_t ipc_key, int size)
 Create the shared memory segment.

int get_shared_memory_segment_sys_id (key_t ipc_key, int size)
 Get the system's identifier of a shared memory segment that has already been created (by another process).

int get_shared_memory_segment_id ()
 Returns the shared memory segment identifier.

SHM_addr attache_shared_memory_segment ()
 Attache a previously created shared memory segment.

SHM_addr get_shm_address ()
 Returns the address used by the process to access the shared memory segment.

int set_shm_auto_destroy ()
 Tell the IPC library to destroy the SHM on the last detachement.

shmid_ds * get_shm_info ()
 Return the data structure that describes the Shared Memory Segment (as documented in man shmget).

int detache_shm ()
 Detache the Shared Memory Segment.


Detailed Description

Header file for shm.c.

Definition in file my_shm.h.


Function Documentation

SHM_addr attache_shared_memory_segment  
 

Attache a previously created shared memory segment.

Returns:
Upon successful completion the function returns the process' address of the memory segment (that is, the address used by the process to access the memory segment). Otherwise, the function returns (SHM_addr)-1.

Definition at line 158 of file shm.c.

References attachement_address, and shm_id.

void change_shm_access_permission int    new_permission
 

Change the SHM's default permissions.

Parameters:
new_permission New permissions to apply to the shared memory (at creation time).
Warning:
By default the permission is 0x000001C0 (grant all rights for the process' user).

Definition at line 32 of file shm.c.

References permissions.

int create_shared_memory_segment key_t    ipc_key,
int    size
 

Create the shared memory segment.

Parameters:
size Size in bytes of the segment.
ipc_key This argument represents the IPC identifier of the shared memory segment. If you know the (well known) identifier's value, then you can specify it. Otherwise, if you want to let the system choose the first available identifier, then you should set 'ipc_key' to (key_t)-1. Please note that an IPC identifier is a value greater or equal to 0.
Returns:
On success, the function may return one of the following values:
  • CREATE_SHM_ALREADY_CREATED: The shared memory segment has already been created.
  • CREATE_SHM_ERROR: An error occured while creating the segment.
  • CREATE_SHM_OK: The shared memory segment has been successfully created.
Once you called create_shared_memory_segment(), you should call get_shared_memory_segment_id() to get the system's identifier assigned to the newly created shared memory segment.

Definition at line 51 of file shm.c.

References CREATE_SHM_ALREADY_CREATED, CREATE_SHM_ERROR, CREATE_SHM_OK, permissions, and shm_id.

int detache_shm  
 

Detache the Shared Memory Segment.

Returns:
If an error occured, the function returns -1. Otherwise, the SHM attachement address is returned.

Definition at line 190 of file shm.c.

References attachement_address.

int get_shared_memory_segment_id  
 

Returns the shared memory segment identifier.

Returns:
The function returns the identifier of the shared memory segment.
Warning:
The identifier should be a value greater or equal to 0. If this function returns -1, it means that an error occured during the creation of the segment or that the segment has not been created.

Definition at line 137 of file shm.c.

References shm_id.

int get_shared_memory_segment_sys_id key_t    ipc_key,
int    size
 

Get the system's identifier of a shared memory segment that has already been created (by another process).

Parameters:
size Size in bytes of the shared memory segment.
ipc_key Well known IPC key that represents the shared memory segment. This key is shared between all processes that access the shared memory segment.
Returns:
The function may return one of the following value:
  • GET_SHM_ALREADY_GET: You've already got the SHA system's identifier.
  • GET_SHM_ERROR: An error occured while getting the SHM system's identifier.
  • GET_SHM_OK: The operation was successful.
Once you've called get_shared_memory_segment_sys_id(), you should call get_shared_memory_segment_id() to get the SHM system's identifier.
Warning:
If you need to call this function, it means that you want to get the system ID of a SHM that has already been created by another process. Then you need to specify a well known IPC key.

Definition at line 92 of file shm.c.

References GET_SHM_ALREADY_GET, GET_SHM_ERROR, GET_SHM_OK, and shm_id.

SHM_addr get_shm_address  
 

Returns the address used by the process to access the shared memory segment.

Returns:
The function returns the address used by the process to access the shared memory segment.

Definition at line 147 of file shm.c.

References attachement_address.

struct shmid_ds* get_shm_info  
 

Return the data structure that describes the Shared Memory Segment (as documented in man shmget).

Returns:
Upon successful completion, the function returns that address of a structure "struct shmid_ds" that describes the SHM (see man shmctl for details about this structure). If an error occured, then the function returns NULL.

Definition at line 174 of file shm.c.

References get_shm_info(), shm_id, and shm_info.

Referenced by get_shm_info().

int set_shm_auto_destroy  
 

Tell the IPC library to destroy the SHM on the last detachement.

Returns:
Upon successful completion, the function return 0, otherwise it returns -1.
Warning:
There are 2 very important things to know:
  • This function should be called by the process that has created the SHM.
  • Once you've called this function, another process can NOT get the shared memory segment (the OS consider that the segment is ready to be destroyed ... so no more process can get it). Therefore you must call this function when you are sure that no more process will try to get the shared memory segment.

Definition at line 124 of file shm.c.

References shm_id.


Generated on Thu Apr 3 16:23:46 2003 for Common_C_libraries by doxygen1.3-rc1