HPlogo MPE/iX Developer's Kit Reference Manual Volume 2: HP 3000 MPE/iX Computer Systems > Chapter 2 SVID IPC Library Function Descriptions

semget

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Returns a semaphore identifier.

Syntax

   #include <sys/types.h>

   #include <sys/ipc.h>

   #include <sys/sem.h>



   int semget (key_t key, int nsems, int semflg);

Parameters

key

Either a user-defined key value to rendezvous with the semaphore set, or IPC_PRIVATE. If IPC_PRIVATE is specified, a new semaphore set is created, but other processes cannot rendezvous by key. Refer to the description of ftok() for details about obtaining user-defined key values

nsems

The number of semaphores in the set. The maximum number of semaphores per set is 4096.

semflg

Valid flags for this function are:

IPC_CREAT

If a semaphore set is not already associated with key, a new semaphore identifier is allocated and a semaphore set and data structure are associated with it. If a semaphore identifier is already associated with key, and IPC_EXCL is not specified, semget() returns the semaphore identifier currently associated with key.

IPC_EXCL

If specified with IPC_CREAT, semget() returns an error if a semaphore identifier is currently associated with key.

MODE

The lower nine bits of semflg contain the access permission bits (similar to the nine-bit mask found in file entries). They define the access rights for the owner, the group, and other users on the system.

Return Values

>=0

Success. A semaphore identifier is returned.

-1

An error occurred, and errno is set to indicate the error condition.

Description

The semget() function returns a semaphore identifier associated with the value passed in key. A semaphore identifier and the associated data structure and semaphore set containing nsems semaphores are created for key if one of the following conditions is true:

  • The value passed in key is equal to IPC_PRIVATE.

  • The value passed in key does not already have a semaphore identifier associated with it, and the semflg specifies IPC_CREAT.

The data structure associated with the new semaphore identifier is initialized to the following values:

sem_perm.cuid

Effective user ID of the calling process (creator user ID)

sem_perm.uid

Effective user ID of the calling process (owner user ID)

sem_perm.cgid

Effective group ID of the calling process (creator group ID)

sem_perm.gid

Effective group ID of the calling process (owner group ID)

sem_perm.mode

Low-order 9 bits are set equal to the low-order 9 bits of semflg

sem_nsems

The value of nsems

sem_otime

0

sem_ctime

Current time

Implementation Considerations

The maximum number of semaphores per set is 4096.

An MPE/iX system manager can use the MPE/iX SVIPC utility to interactively configure:

  • The maximum number of semaphores in a semaphore set

  • The maximum value for a semaphore

  • The maximum semaphore operation value

  • The maximum semaphore adjust value

  • The maximum number of semaphore sets allowed system wide

  • The maximum number of semaphore operations allowed per semop() call

Refer to the section "Managing SVID IPC Services" for more information.

Errors

If an error occurs, errno is set to one of the following values.

EACCESCAUSE A semaphore identifier exists for key and the calling process does not have permission (specified by the low-order 9 bits of semflg).
 ACTION Ensure the calling process has access permissions required to access the existing semaphore identifier.
EEXISTCAUSE A semaphore identifier exists for key and semflg specifies both IPC_CREAT and IPC_EXCL.
 ACTION To access the existing identifier for key, retry the operation without the IPC_EXCL option. To create a new semaphore set with IPC_EXCL, a unique key must be specified.
EINVALCAUSE nsems is either less 1 or greater than the system-defined limit, or a semaphore identifier exists for key and the number of semaphores in the set is less than nsems and nsems is not equal to 0.
 ACTION If accessing an existing semaphore set, make sure the nsems value does not exceed the number of semaphores in the existing set. If creating a new semaphore set, make sure nsems does not exceed the system-defined limit.
ENOENTCAUSE A semaphore identifier does not exist for key and semflg does not specify IPC_CREAT.
 ACTION If attempting to access an existing semaphore set, make sure the right key value was specified. If a new semaphore set should be created for that key if none exists, then make sure IPC_CREAT is specified.
ENOSPCCAUSE The number of semaphore identifiers would exceed the system-defined limit.
 ACTION None. The operation can be retried if another semaphore identifier is removed from the system.
ESYSERRCAUSE An operating system error occurred that does not map directly to any of the above errors.
 ACTION Examine the MPE/iX process error stack for the type of system error.

See Also

semctl(), semop(), SVID2 (Section 12)

Feedback to webmaster