- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: What is semaphore in Unix
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 01:09 AM
тАО02-28-2003 01:09 AM
What is semaphore in Unix
I got details to calculate semaphore kernal
parameters in Unix for Oracle.
But I do not know what is semaphore.
Can you please explain about semaphore
for better understanding.
Thanks
R. Ezhil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 01:20 AM
тАО02-28-2003 01:20 AM
Re: What is semaphore in Unix
Heres more detail;
http://www.docs.hp.com/cgi-bin/fsearch/framedisplay?top=/hpux/onlinedocs/TKP-90202/TKP-90202_top.html&con=/hpux/onlinedocs/TKP-90202/00/00/26-con.html&toc=/hpux/onlinedocs/TKP-90202/00/00/26-toc.html&searchterms=semaphore&queryid=20030228-021118
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 01:24 AM
тАО02-28-2003 01:24 AM
Re: What is semaphore in Unix
a classic resource-sharing problem:
-- . Dining Philosophers ------
Philosophers do two things:
o Think
o Eat
Thinking is solitary
Eating involves shared resources - a spagetti restaurant with too few forks
#define N = 5; /* five forks */
define philosopher(int i);
repeat forever {
think();
take_fork(i);
take_fork((i + 1) mod N);
eat();
put_fork(i);
put_fork((i + 1) mod N);
}
end
What if everyone picks up the first fork? - deadock
Put down and retry - starvation
Put down and random wait - possible starvation
Need a secure mechanism
Use a mutex
#define N = 5; /* five forks */
semaphor mutex = 1;
define philosopher(int i);
repeat forever {
think();
down(mutex);
take_fork(i);
take_fork((i + 1) mod N);
eat();
put_fork(i);
put_fork((i + 1) mod N);
up(mutex);
}
end
Only allows one philosopher to eat
With 5 forks, 2 could eat!
-- . corect solution ----
Philosophers in 1 of 3 states:
o Thinking
o Hungry
o Eating
Blocking semaphor for each philosopher - may be hungry, but wait to eat.
3 state transitions. Transitions performed in critical region control by mutex
semaphor.
Thinking -> Hungry: set "hungry" state, and try next transition
Hungry -> Eating: block if either neighbour eating, otherwise take forks and
set "eating" state
Eating -> Thinking: release forks, set "thinking" state, try to unblock
neighbours
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 01:28 AM
тАО02-28-2003 01:28 AM
Re: What is semaphore in Unix
Ref:
Semaphores are a programming construct designed by E. W. Dijkstra in the late 1960s. Dijkstra's model was the operation of railroads: consider a stretch of railroad in which there is a single track over which only one train at a time is allowed. Guarding this track is a semaphore. A train must wait before entering the single track until the semaphore is in a state that permits travel. When the train enters the track, the semaphore changes state to prevent other trains from entering the track. A train that is leaving this section of track must again change the state of the semaphore to allow another train to enter. In the computer version, a semaphore appears to be a simple integer. A process (or a thread) waits for permission to proceed by waiting for the integer to become 0. The signal if it proceeds signals that this by performing incrementing the integer by 1. When it is finished, the process changes the semaphore's value by subtracting one from it.
Semaphores let processes query or alter status information. They are often used to monitor and control the availability of system resources such as shared memory segments.
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 01:40 AM
тАО02-28-2003 01:40 AM
Re: What is semaphore in Unix
Hi,
semaphores basically used for processes synchronization
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 05:23 AM
тАО02-28-2003 05:23 AM
Re: What is semaphore in Unix
A semaphore is used when more than one thread or process need to share a resource (a disk, shared memory, etc).
The kernel and processes work together with the semaphores so that only one process gets to use the resource at a time. The kernel will grant permission to the semaphore (and resource) to only one process at a time.
For every resource, there is a semaphore. So, if you have 10 semaphores, you have 10 shared resources.
I hope this helps you understand.
Vince
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 05:24 AM
тАО02-28-2003 05:24 AM
Re: What is semaphore in Unix
Semaphores can be thought of as flags (hence their name, semaphores). They are either on or off. A process can turn on the flag or turn it off. If the flag is already on, processes who try to turn on the flag will sleep until the flag is off. Upon awakening, the process will reattempt to turn the flag on, possibly suceeding or possibly sleeping again.
Such behaviour allows semaphores to be used in implementing a post-wait driver - a system where processes can wait for events (i.e. wait on turning on a semphore) and post events (i.e. turning of a semaphore).
For instance, in Oracle, this is used to maintain concurrency control over the SGA, to control concurrency between all the background processes (pmon, smon, dbwr, lgwr, and oracle shadows), since it is writeable by all processes attached. Semaphores are also used to control two-task communication between the user process and shadow process if the fast (shared memory) driver is used.
There are three OS kernel parameters that work together to limit semaphore allocation (SEMMNI, SEMMSL(hardcoded to 500) & SEMMNS ).
Current semaphore allocation can be displayed with the
OS command 'ipcs -s'.
% ipcs -s
Hope this helps!
Best Regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-28-2003 10:55 AM
тАО02-28-2003 10:55 AM
Re: What is semaphore in Unix
Semaphores are used mainly to keep processes properly synchronized to prevent collisions when accessing shared data structures.
Refer the URL,
http://docs.hp.com/cgi-bin/otsearch/getfile?id=/hpux/onlinedocs/939/KCParms/KCparam.SemaParmsOverview.html&searchterms=semaphore&queryid=20030228-120153
-Vijay