Showing results for 
Search instead for 
Did you mean: 

What is a Semaphore?

Go to solution
Honored Contributor

What is a Semaphore?

Hi I need to find some information on semaphores and how the kernel tuning parameters will affect my system relating to this.

I had believed that a semaphore was some type of a polling lock on memory? Although this was probably specific to an application I was looking at a long time ago.

Can anyone explain in bog english! the semaphore?

It works for me (tm)
Paula J Frazer-Campbell
Honored Contributor

Re: What is a Semaphore?

Hi Bill

A semaphore is a flag of a process state and can be related to memory.

A semaphore can store just about anything:-
File process state
User count
Record locks

Universe uses semaphore for :-

? File lock semaphores
? Group/update record lock semaphores
? Login semaphore
? Port status semaphore
? Dynamic file semaphore
? Transaction logging semaphore


If you can spell SysAdmin then you is one - anon
James R. Ferguson
Acclaimed Contributor

Re: What is a Semaphore?

Hi Bill:

A chapter on semaphores can be found in the "HP-UX MultiProcessing White Paper":

Information on kernel configuration parameters relating to semaphores can be found here:


Respected Contributor

Re: What is a Semaphore?

Hi Bill,

A semaphore is a memory data which store a
counter. You can access semaphore by semXXX
functions (in C, semget, semop,...). System
assume that only one processe can access to
this memory space in a same moment.
A semaphore can be share between some processes
to communicate (locks, ...).

Semaphores are parts of IPC (InterProcess
Communication), so you can make some operations
using ipcs and ipcrm commands (see man page
for details).

There are 3 kernel parameters for tuning :
semmns, semmni ,semmap. Refer to documentations
for details, but you need with DB you seems to
need more semaphores (For file and memory
locking) .For share memory (IPC part also you
have shmXXX parameters)



Respected Contributor

Re: What is a Semaphore?

Hi Bill,

The name Semaphore is taken from that when which allow one train to access unique rail at one specific time ( this prevent from train crash ).

When you have a critical section lets say a printer, when you use a semaphore ( private semaphore ) this allows only one job to be printed at a time when it finishes another single job can be printed.

Other Semaphores can have n number of concurent process simultanously running on the same ressource and each time one finish the first process in the waiting list will take place in manipulating the ressource.

When a process look for a ressource it executes a P function and when it finishes it executes a V function. each V function executed allow a process, which had exeecuted a P and in the waiting list, to manipulate the ressource.

Example: When a user updates an oracle row, the Oracle rdbms prevent any other process from doing other updates on that row till the first process finishes with.
Respected Contributor

Re: What is a Semaphore?

Hi again,

A semaphore is a counter used to provide access to a shared data object ( or a resource ) for multiple process. To obtain a shared resource aprocess needs to do the following :

1. Test the semaphore that controls the resource.
2. If the value of the semaphore is positive, the process can use the resource. The process decrements the semaphore value by one, indicating that it has used one unit of the resource.

If the value of the semaphore is 0, the process goes to sleep until the semaphore value is greater than 0 ( ie. when a process finish with a resource it MUST increase the value of the semaphore counter by one, and this wake up the schedular to honor the first process in the waiting queue ).

The Unix kernel maintains a semid_ds structure for each semafore :

struct semid_ds {
struct ipc_perm sem_perm ;
struct sem *sem_base; /* pointer to first semafore in set */
ushort sem_nsems; /* Number of semaphores in set */
time_t sem_otime; /* last-semop() time */
time_t sem_ctime; /* last-change time */

struct sem {
ushort semval; /* semaphore value */
pid_t sempid; /* pid for last operation */
ushort semncnt; /*number of process awaiting semval > currval */
ushort semzcnt; /* number of process awaiting semval = 0 */

Kernel variables :

SEMVMX : max value of any semaphores.
SEMAEM : max value of any semaphore's adjust-on-exit value.
SEMMNI : max number of semaphore sets.
SEMMNS : max number of semaphores.
SEMMSL : max number of semaphores per semaphore set.
SEMMNU : max number of undo structures.
SEMUME : max number of undo entries per undo structures.
SEMOPN : max number of operations per semop call.

I can give you more if you want !
Manoj Caisucar
Occasional Visitor

Re: What is a Semaphore?

i would like to know how to find the information on windows m/c
how many semaphores are active at a given time .

Like how we have the command ipcs on linux to get the status
how to get it on windows