我试图允许其他用户的程序修改我的信号量(基本上是删除它),但它失败了。
下面是我的信号量创建命令:
if ((semID = semget(key, 2, IPC_CREAT | 0777)) == -1) {
perror("Sem Creation:");
exit(2);
}仍然由其他用户运行的程序无法删除“Not”错误的信号量
发布于 2014-11-30 05:36:39
根据semctl
IPC_RMID立即删除信号量集,唤醒在semop(2)调用中阻塞的所有进程(返回错误并将errno设置为EIDRM)。调用进程的有效用户ID必须与信号量集的创建者或所有者匹配,否则调用方必须具有特权。
因此,试图删除信号量的进程必须具有所有者或创建者的用户ID,或者是超级用户。
编辑:您可以使用semctl()和IPC_SET选项来设置信号量的ipc_perm结构的uid字段(所有者id)。这样,您就可以将所有权传递给另一个用户id (创建者id没有更改)。请参阅我链接到的手册页,并阅读有关IPC_SET的部分。
发布于 2014-11-30 05:09:38
here is what you need to know about semaphore creation/removal
Notice that a named semaphore is created using sem_open() NOT semget()
POSIX semaphores come in two forms: named semaphores and unnamed
semaphores.
Named semaphores
A named semaphore is identified by a name of the form
/somename; that is, a null-terminated string of up to
NAME_MAX-4 (i.e., 251) characters consisting of an initial
slash, followed by one or more characters, none of which are
slashes. Two processes can operate on the same named
semaphore by passing the same name to sem_open(3).
The sem_open(3) function creates a new named semaphore or
opens an existing named semaphore. After the semaphore has
been opened, it can be operated on using sem_post(3) and
sem_wait(3). When a process has finished using the semaphore,
it can use sem_close(3) to close the semaphore. When all
processes have finished using the semaphore, it can be removed
from the system using sem_unlink(3).https://stackoverflow.com/questions/27210008
复制相似问题