Jack cole
Jack cole

Reputation: 447

How to implement a pipe using shared memory and semaphores?

My current assignment is regarding implementing the pipe() in Linux using shared memory.

Since this is my first time working with semaphores & shared memory (mutex also) I have zero experience with it .

Can somebody shed some light on it with explanation regarding its implementation ? thanks

Upvotes: 4

Views: 1199

Answers (1)

Manos
Manos

Reputation: 2186

Start with the man pages below:

Shared memory

ftok
shmget
shmat
shmctl
shmdt

Semaphores

sem_init
sem_wait
sem_post

The idea is, two different applications that will use your pipe to be able to exchange data. This can be done with shared memory. Also some synchronization should be done (here comes the semaphore) in order to be sure that the data that a process reads are consistent. For example, you have to block process A writing to the pipe until process B reads the data from the pipe from a previous write.

Upvotes: 3

Related Questions