- What is difference between semaphore and a shared memory ?
- can I use semaphores between two different processes or it must be used only in threads of a same process ?
Asked
Active
Viewed 3,429 times
4

Waqas
- 191
- 3
- 4
- 13
-
[Semaphore](http://en.wikipedia.org/wiki/Semaphore_(programming)) [Shared Memory](http://en.wikipedia.org/wiki/Shared_memory) – Arnab Nandy Nov 16 '14 at 17:06
2 Answers
3
Yes, you can use semaphore between two different processes
Choose a name for your semaphore
#define SNAME "/mysem"
Use sem_open with O_CREAT in the process that creates them
sem_t *sem = sem_open(SNAME, O_CREAT, 0644, 3); /* Initial value is 3. */
Open semaphores in the other processes
sem_t *sem = sem_open(SEM_NAME, 0); /* Open a preexisting semaphore. */

Community
- 1
- 1

Arnab Nandy
- 6,472
- 5
- 44
- 50
-
this is answer of part 2 only the part one given in your comment check it – Arnab Nandy Nov 16 '14 at 17:29
3
The semaphore is a system for synchronization 2 or plus process to access a shared resource.
The shared memory is a system for sharing a piece of memory between 2 o plus process, on the shared memory is possible write or read data to and from a process.
For example with a semaphore is possible to manage the access to shared memory for avoid the read o write non synchronized from 2 process.
Bye

Mario Cimini
- 62
- 3