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 :
- What's is the difference between a pipe that's implemented in Posix vs a pipe that's implemented in System-V ?
- What calls would I need for implementing the above library using the
Sys Vversion ?
Thanks
With regards to question (1) - there should be no differences between a
Posiximplementation of a pipe and aSystem Vimplementation 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 Vare:shmgetto createshmatto access andshmctlto destroy (shmdtis used to unmap the shared memory segment from the current process).You use a call to
ftokwhich 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 usesemopand to destroy it you usesemctl.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