Linking to a shared memory segmentΒΆ

link_shared_memory()

Linking to a shared memory segment


SYNTAX

link_shared_memory(share_name, record_id | file_id, perms, options)

Link to the shared memory segment whose name is share_name and associate it with the specified file or record buffer.

The shared memory segment must have already have been created by another program, using the create_shared_memory() function. The record buffer should have exactly the same structure as the one specified in the program that created the shared memory segment. If it does not, the results are undefined.

share_name, options

The values of share_name and options must match those used by the process that created the shared memory segment. See create_shared_memory() for full details of these arguments.

record_id | file_id

The identifier of the record structure (!record) or file (![o]file ) to be linked to the shared memory segment.

perms

The access permission required. This should be one of the following values (defined in $SCULPTOR/include/files.h):

PERMS_R

Read permission only required

PERMS_RW

Read and write permission required

The return value from the function must be stored in an i4 type field. If the function was successful, the return value is non-zero and is used to identify this shared memory segment in calls to other shared memory functions.

A return value of zero means that the function failed. The error number is stored in sys.Errno. The normal reason for failure is that the shared memory segment has not been created.


EXAMPLE

!record shmrec {
     fieldlist
}

!temp shmid,,i4

     shmid = link_shared_memory("shm_segjx", shmrec, PERMS_R, 0)
     if (shmid == 0) {
          error "Error linking to shared memory segment: errno = " + tostr(sys.Errno)
          exit
     }

Shared memory functions

create_shared_memory()

Create a shared memory segment

link_shared_memory()

Link to an existing shared memory segment

read_shared_memory()

Read the current field values from shared memory into associated record buffer

write_shared_memory()

Write the current values from associated record buffer into shared memory

unlock_shared_memory()

Unlock a shared memory segment

unlink_shared_memory()

Unlink a program from a shared memory segment


RELATED TOPICS

Shared memory options in sculptor.h

create_msg_queue()

!record

![o]file