Difference between a shared memory based pipe , in Posix vs System V?

618 Views Asked by At

As part of my homework project I had to implement a library that implements a pipe using shared memory. Both the anonymous and named pipe .

I chose the Posix implementation , meaning , I used the following calls :

mmap()
shm_open()
ftruncate()
shm_unlink()

For semaphores and synchronization 

sem_init()
sem_getvalue()
sem_wait()
sem_post()

(I might forgot one or two calls)

My TA told me that he prefers that I'd implement that library with System V version , however since I'm in the middle of my exams , I have no extra time to do that (would take a least a week , I guess) .

My questions are :

  1. What's is the difference between a pipe that's implemented in Posix vs a pipe that's implemented in System-V ?
  2. What calls would I need for implementing the above library using the Sys V version ?

Thanks

1

There are 1 best solutions below

0
Anya Shenanigans On BEST ANSWER

With regards to question (1) - there should be no differences between a Posix implementation of a pipe and a System V implementation of a pipe - if you're implementing a library with a set of routines, then the user should not see any difference between the two implementations.

For the developer, the shared memory calls that are used for System V are: shmget to create shmat to access and shmctl to destroy (shmdt is used to unmap the shared memory segment from the current process).

You use a call to ftok which converts a filename into the key that you will use.

Note that the key is the magic uniquification item that distinguishes between the different shared memory/semaphore items.

For getting semaphores you use semget, to lock and unlock you use semop and to destroy it you use semctl.

System V semaphores and shared memory segments can survive beyond the execution of a program - i.e. if the program terminates without destroying them, then they will remain in the system until they are destroyed or recreated either programmatically, or using ipcrm