DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Interprocess communication

Operations on semaphores

This section describes how to use the semop system call. The accompanying program illustrates its use.

Using semop

The synopsis found on the semop(S) manual page is as follows:

   #include <sys/types.h>
   #include <sys/ipc.h>
   #include <sys/sem.h>
   

int semop (int semid, struct sembuf *sops, size_t nsops)

The semop system call requires three arguments to be passed to it and returns an integer value which will be zero for successful completion or -1 otherwise.

The semid argument must be a valid, non-negative, integer value. In other words, it must have already been created by using the semget system call.

The sops argument points to an array of structures in the user memory area that contains the following for each semaphore to be changed:

The *sops declaration means that either an array name (which is the address of the first element of the array) or a pointer to the array can be used. sembuf is the ``tag'' name of the data structure used as the template for the structure members in the array; it is located in the sys/sem.h header file.

The nsops argument specifies the length of the array (the number of structures in the array). The maximum size of this array is determined by the SEMOPM system-tunable parameter. Therefore, a maximum of SEMOPM operations can be performed for each semop system call.

The semaphore number (sem_num) determines the particular semaphore within the set on which the operation is to be performed.

The operation to be performed is determined by the following:

The following operation commands (flags) can be used:


Next topic: Example program
Previous topic: semctl system call example

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005