首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C-信号量权利发行

C-信号量权利发行
EN

Stack Overflow用户
提问于 2014-11-30 04:29:27
回答 2查看 247关注 0票数 0

我试图允许其他用户的程序修改我的信号量(基本上是删除它),但它失败了。

下面是我的信号量创建命令:

代码语言:javascript
复制
  if ((semID = semget(key, 2, IPC_CREAT | 0777)) == -1) {
    perror("Sem Creation:");
              exit(2);
   }

仍然由其他用户运行的程序无法删除“Not”错误的信号量

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 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的部分。

票数 0
EN

Stack Overflow用户

发布于 2014-11-30 05:09:38

代码语言:javascript
复制
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).
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27210008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档