Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is semaphore an IPC mechanism?

Tags:

semaphore

ipc

Is semaphore an IPC mechanism?

like image 383
aks Avatar asked Feb 11 '10 08:02

aks


People also ask

What is semaphore in IPC?

Semaphores are commonly use for two purposes: to share a common memory space and to share access to files. Semaphores are one of the techniques for interprocess communication (IPC). The C programming language provides a set of interfaces or "functions" for managing semaphores. This was last updated in April 2019.

What are the IPC mechanisms?

IPC is the way by which multiple processes or threads communicate among each other. IPC in OS obtains modularity, computational speedup and data sharing. Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO.

Is FIFO an IPC mechanism?

In computing, a named pipe (also known as a FIFO) is one of the methods for inter-process communication.

Is LIFO an IPC mechanism?

Stack uses LIFO (Last-In-First-Out) mechanism for storing local or automatic variables, function parameters and storing next address or return address. The return address refers to the address to return after completion of function execution.


2 Answers

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

like image 188
Lokesh Avatar answered Oct 21 '22 08:10

Lokesh


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.

like image 24
asveikau Avatar answered Oct 21 '22 09:10

asveikau