1825776 Members
1961 Online
109687 Solutions
New Discussion

Semaphores and processes

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Semaphores and processes

HI,

What is the difference between semaphores and processes? How are they dependent on one another? when do semaphores occur?

How do I check for the number of semaphores running?

Thanks
2 REPLIES 2
Steve Steel
Honored Contributor
Solution

Re: Semaphores and processes

Hi


look at sar -m for the semaphore activity or get glance plus.


Fromm www.docs.hp.com search on semaphores

Overview of Semaphore Parameters
System V IPC semaphores are used mainly to keep processes properly synchronized to prevent collisions when accessing shared data structures. Their use in software tends to be complex, so many programmers use alternate means of control where practical.

Semaphore Operations
The semget() system call allocates an array containing a specified number of semaphores (see HP-UX Reference entry semget(2)). Assigning an array with only one semaphore in the set is usually the most sensible for keeping programs reasonably simple. Subsequent semaphore operations are performed atomically on the entire array; individual semaphores in the array are manipulated by an array of semaphore operations (see semop(2) ). semctl() is used to ascertain or change a semaphore's permissions, change time, or owner (see semctl(2)).

Semaphores are typically incremented by a process to block other processes while it is performing a critical operation or using a shared resource. When finished, it decrements the value, allowing blocked processes to then access the resource. Semaphores can be configured as binary semaphores which have only two values: 0 and 1, or they can serve as general semaphores (or counters) where one process increments the semaphore and one or more cooperating processes decrement it. To prevent undetectable overflow conditions, the kernel imposes a maximum value limit beyond which semaphores cannot be incremented. This limit, defined by the semvmx kernel parameter, must not exceed the maximum value of an unsigned integer (65535). Semaphores are not allowed to have negative (less than zero) values.

Semaphore Undo Operations
It may occasionally be necessary when errors occur, a process must abort, a process dies, etc., to change one or more semaphores to a new or previous value. This is called undoing a semaphore. Since the value of any semaphore when such conditions occur is unpredictable, the system enforces a limit on how much the value of a semaphore can change any undo operation. This limit is defined by the semaem kernel parameter.

For more information about System V IPC semaphore operation, consult an advanced UNIX programming text such as Advanced UNIX Programming by Marc J. Rochkind, Prentice-Hall, Inc., ISBN 0-13-011800-1.

Semaphore Limits
Configurable kernel parameters are available to limit the number of sets of semaphores that can exist simultaneously on the system and the total number of individual semaphores available to users that can exist simultaneously on the system. A fixed limit on the number of semaphores that can exist in a set (500) is not configurable.



Steve steel
If you want truly to understand something, try to change it. (Kurt Lewin)
James Murtagh
Honored Contributor

Re: Semaphores and processes

Hi,

A process is the instance of a running program. Semaphores are used to keep processes properly synchronized when accessing shared data structures. So if one process is writing to an area and another process attempts to do the same, a sempahore will block the second process.

Semaphores are used when accessing shared resources, like shared memory, or withing the kernel to access global resources like the page table on multiprocessor systems.

You can view semaphores using "ipcs -sb", look for the NSEMS (number of semaphores) in the last column.

Regards,

James.