Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

47. System V Semaphores > Creating or Opening a Semaphore Set

Creating or Opening a Semaphore Set

The semget() system call creates a new semaphore set or obtains the identifier of an existing set.

#include <sys/types.h>        /* For portability */
#include <sys/sem.h>

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

Note

Returns semaphore set identifier on success, or -1 on error

The key argument is a key generated using one of the methods described in IPC Keys (i.e., usually the value IPC_PRIVATE or a key returned by ftok()).

If we are using semget() to create a new semaphore set, then nsems specifies the number of semaphores in that set, and must be greater than 0. If we are using semget() to obtain the identifier of an existing set, then nsems must be less than or equal to the size of the set (or the error EINVAL results). It is not possible to change the number of semaphores in an existing set.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint