IBM Version 4 Universal Remote User Manual


 
sends one, or that a message exist on the queue before a process requests to
receive one.
A semaphore is a synchronization mechanism similar to a mutex or a machine
interface (MI) lock. It can be used to control access to shared resources, or used
to notify other processes of the availability of resources.
Processes can communicate directly with one another by sharing parts of their
memory space and then reading and writing the data stored in the shared
memory. Synchronization of shared memory is the responsibility of the application
program. Semaphores can be used to synchronize shared memory use across
processes. Mutexes or condition variables can be used to synchronize shared
memory use across threads.
Although each IPC service provides a specific type of interprocess communication,
the three services share many similarities. Each service defines a mechanism
through which its communications take place. For message queues, that mech-
anism is a message queue; for semaphores, it is a semaphore set; and for shared
memory, it is a shared memory segment. These mechanisms are identified by a
unique positive integer, called, respectively, a message queue identifier (
msqid
), a
semaphore identifier (
semid
), and a shared memory identifier (
shmid
).
Associated with each identifier is a data structure that contains state information for
the IPC mechanism, as well as ownership and permissions information. This struc-
ture is similar to a file permissions structure, and is initialized by the process that
creates the IPC mechanism. It is then checked by all subsequent IPC operations
to determine if the requesting process has the required permissions to perform the
operation.
To get an identifier, a process must either create a new IPC mechanism or access
an existing mechanism. This is done through the msgget(), semget(), and
shmget() functions. Each get operation takes as input a
key
parameter and
returns an identifier. Each get operation also takes a
flag
parameter. This
flag
parameter contains the IPC permissions for the mechanism as well as bits that
determine whether or not a new mechanism is created.
When a message queue, semaphore set, or shared memory segment is created,
the process that creates it determines how it can be accessed. Subsequent IPC
operations do a permission test for the calling process before allowing the process
to perform the requested operation.
Signal APIs
An X/Open** specification defines a signal
1
as “a mechanism by which a process
may be notified of, or affected by, an event occurring in the system.” The term
signal is also used to refer to the event itself.
A signal is said to be generated
when the event that causes the signal first occurs.
Examples of such events include the following:
System-detected errors
Timer expiration
1
X/Open CAE Specification System Interface Definitions Issue 4, Number 2, Glossary, page 27. X/Open Company Ltd., United
Kingdom, 1994.
Chapter 8. Use of OS/400 APIs
8-23