n**d 发帖数: 9764 | 1 【 以下文字转载自 Linux 讨论区 】
发信人: noid (DoIneedit?), 信区: Linux
标 题: Semaphores in Linux
发信站: BBS 未名空间站 (Sat Jan 10 00:14:53 2009)
http://www.linuxdevcenter.com/pub/a/linux/2007/05/24/semaphores-in-linux.html?page=1
in this link, the author says "In general, the older Unix-based systems uses
the System V version and the current Linux-based systems use the POSIX
version."
The System V uses semget()... and POSIX uses sem_init...
However, in my company's Linux system, the gcc compiles semget()...
succesfu | T*****9 发帖数: 2484 | 2 头文件不一样
uses
【在 n**d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 【 以下文字转载自 Linux 讨论区 】 : 发信人: noid (DoIneedit?), 信区: Linux : 标 题: Semaphores in Linux : 发信站: BBS 未名空间站 (Sat Jan 10 00:14:53 2009) : http://www.linuxdevcenter.com/pub/a/linux/2007/05/24/semaphores-in-linux.html?page=1 : in this link, the author says "In general, the older Unix-based systems uses : the System V version and the current Linux-based systems use the POSIX : version." : The System V uses semget()... and POSIX uses sem_init... : However, in my company's Linux system, the gcc compiles semget()...
| n**d 发帖数: 9764 | 3 I know the differnce between System V and POSIX for Semaphore. My question
is what kind of Semaphore Linux supports, System V or POSIX.
【在 T*****9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 头文件不一样 : : uses
| T*****9 发帖数: 2484 | 4 try to use the -lphread option when you compiler with gcc
【在 n**d 的大作中提到】![](/moin_static193/solenoid/img/up.png) : I know the differnce between System V and POSIX for Semaphore. My question : is what kind of Semaphore Linux supports, System V or POSIX.
| n**d 发帖数: 9764 | 5 Yes, we can use gcc with -lrt or -lpthread to pass compile and link. What
does it mean? So can we say Linux supports both kinds of Semaphores?
【在 T*****9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : try to use the -lphread option when you compiler with gcc
| r*********r 发帖数: 3195 | 6 不奇怪. 可能两种都支持. Sys V 的强大, 但难用.
Posix 语义更清楚. 经常是 posix 的用 sys v 来实现, 本身只是一个wrapper.
但是 posix 又分两种, 有名的是 sem_open, 无名是 sem_init.
有可能系统只支持 sem_open, 因为 sem_init 只能用于线程, 不能用作 ipc. | n**d 发帖数: 9764 | 7 How do we use System V Semaphores for unrelated processes (not forked one)?
Some example code uses Ftok("filename" ...) to generate the key. So if the 2
processes use the same filename then they can get the same key.
More often, we use IPC_PRIVATE for the key. In this case, how can the 2
processes get the same key? Does that mean we have to use Ftok() if we want
to use Sys V Semaphores for 2 unrelated processes?
【在 r*********r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 不奇怪. 可能两种都支持. Sys V 的强大, 但难用. : Posix 语义更清楚. 经常是 posix 的用 sys v 来实现, 本身只是一个wrapper. : 但是 posix 又分两种, 有名的是 sem_open, 无名是 sem_init. : 有可能系统只支持 sem_open, 因为 sem_init 只能用于线程, 不能用作 ipc.
| r*********r 发帖数: 3195 | 8 用 IPC_PRIVATE 就不能 share. | n**d 发帖数: 9764 | 9 Besides Ftok(), is there any other way?
【在 r*********r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 用 IPC_PRIVATE 就不能 share.
| r*********r 发帖数: 3195 | 10 如果你已经通过其它方法拿到了 key (比如 ipcs), 就不需要 ftok. |
|