Operating System - HP-UX
1820591 Members
1959 Online
109626 Solutions
New Discussion юеВ

IPC's - shared memory, semaphores and messages.

 
Manuales
Super Advisor

IPC's - shared memory, semaphores and messages.

Could you please explain me what are the IPCS
i know there are 3:

shared memory, semaphores and messages,

why do they exist?
when are they used?
how are they used?
who do they use?

please let me know.
Thanks.

do you know a link to know more about it?
:0)
4 REPLIES 4
Dennis Handly
Acclaimed Contributor

Re: IPC's - shared memory, semaphores and messages.

All these three things are ways for processes to talk to other processes. (Other than pipes and files.)

With shared memory, you can share data by just loads/stores.
Semaphores are how you can also synchronize processes.
And you can also send messages to other processes.

Some links:
http://docs.hp.com/en/5187-2783/ch10s09.html
http://docs.hp.com/en/TKP-90202/ch06.html
Sandeep_Chaudhary
Trusted Contributor

Re: IPC's - shared memory, semaphores and messages.

suxde900 # man ipcs

ipcs(1) ipcs(1)

NAME
ipcs - report status of interprocess communication facilities

SYNOPSIS
ipcs [-mqs] [-abcopt] [-C core] [-N namelist]

DESCRIPTION
ipcs displays certain information about active interprocess
communication facilities. With no options, ipcs displays information
in short format for the message queues, shared memory segments, and
semaphores that are currently active in the system.

What is semaphore?

A semaphore is a type of Interprocess communication resource used for synchronization and mutual exclusion between any two asynchronous processes.

why?when?who?when?

Semaphores are used to cap the number of accesses to a given resource to a maximum number.

For example (and this is not a good example), if you have a multithreaded application, where threads are reading a file, you could create a semaphore to make sure that only 5 threads could read from the file at any given time. If there were 5 threads reading the file at some point and time, and another (6th) thread wanted to read the file, the semaphore would block access until one of the other 5 was finished.
Dennis Handly
Acclaimed Contributor

Re: IPC's - shared memory, semaphores and messages.

>Sandeep: For example (and this is not a good example), if you have a multithreaded application

For threads, you would typically use mutexes and condition variables. So just replace thread by process above. :-)
James R. Ferguson
Acclaimed Contributor

Re: IPC's - shared memory, semaphores and messages.

Hi Manuales:

The word "semaphore" derives from the Greek word for "flag" or "signal". As such, it is a variable used to control access to some common resource: a file; a piece of shared memory, etc.

A semaphore holds a zero or positive count that denotes the number of a resource that is available. One speaks of "P" and "V" operations to "dePlete" and "reVive" the count. Semaphores implement "locks" to resources.

A "P" operation decrecemnts a resource count. IF the count is zero, the process attempting to do the operation is suspended (waits). A "V" operation increcemnts the semaphore count, allowing another waiting process to resume execution. A binary semaphore (i.e one with states (counts) of only 0 and 1) implements a simple "lock" to a resource.

Semaphores form the basis for any multi-threading environement. WIthout them, it would be a city without traffic lights!

Regards!

...JRF...