[英]Difference between a shared memory based pipe , in Posix vs System V?
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 : 我选择了
Posix
实现,也就是说,我使用了以下调用:
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) . 我的助教告诉我,他希望我使用
System V
版本来实现该库,但是由于我正处于考试中间,所以我没有多余的时间来这样做(我想至少要花一周的时间) 。
My questions are : 我的问题是:
Sys V
version ? Sys V
版本实现上述库需要什么调用? Thanks 谢谢
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. 关于问题(1)-管道的
Posix
实现与管道的System V
实现之间应该没有差异-如果您要通过一组例程来实现库,那么用户应该看不到任何差异在两个实现之间。
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). 对于开发人员,用于
System V
的共享内存调用是: shmget
创建shmat
进行访问, shmctl
销毁( shmdt
用于从当前进程取消映射共享内存段)。
You use a call to ftok
which converts a filename into the key that you will use. 您可以使用
ftok
调用,它将文件名转换为将要使用的密钥。
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
. 要获取信号量,请使用
semget
,使用semop
进行锁定和解锁,然后使用semctl
销毁它。
System V semaphores and shared memory segments can survive beyond the execution of a program - ie 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
System V信号量和共享内存段可以在程序执行后继续存在-即,如果程序在不破坏它们的情况下终止,那么它们将保留在系统中,直到通过编程或使用
ipcrm
销毁或重新创建它们为止
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.