tags:

views:

290

answers:

5

Is semaphore an IPC mechanism?

+2  A: 

It depends on the operating system

In Windows named semaphores can be accessed between processes using the CreateSemaphore() and OpenSemaphore() functions

http://msdn.microsoft.com/en-us/library/ms682438%28VS.85%29.aspx

sergiom
A: 

A semaphore is not a tool and is not tied to any operating system or any programming language. It's more like a Pattern.

Wikipedia says :

In computer science, a semaphore is a protected variable or abstract data type which constitutes a classic method of controlling access by several processes to a common resource in a parallel programming environment.

Source : Wikipedia

A.Chatellier
+3  A: 

Yes, under many platforms semaphores can synchronize across processes. You would use "named" semaphores for this -- multiple processes access the object via a name, similar to filesystem objects.

In POSIX, you can create named semaphores via sem_open(). For unamed semaphores, if the second parameter to sem_init() is nonzero, it can be interprocess, though I'm not sure exactly how an unnamed interprocess semaphore is supposed to work.

Note that on some systems these functions may fail with ENOSYS if interprocess semaphores aren't supported (for example OpenBSD).

In Windows, you can create named semaphores via CreateSemaphore() as @sergiom has mentioned.

asveikau
A: 

POSIX semaphores can be unnamed or named. Unnamed semaphores are allocated in process memory and initialized. Unnamed semaphores might be usable by more than one process, depending on how the semaphore is allocated and initialized. [...]

Would you like to know more?

sum1stolemyname
A: 

Actually Semaphore is a synchronisation tool but it is counted as an IPC bcoz it is accessed by more than 1 process

Lokesh