Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-28-2006, 02:02 AM   #1
LQ Newbie
Registered: Sep 2006
Posts: 2

Rep: Reputation: 0
permission denied error creating POSIX semaphores


Can anyone tell me what area I should be looking in to solve a permission denied error when creating a POSIX semaphore?

I understand that the error means:
the semaphore already exists, and the permissions specified are denied OR the semaphore does not exist, and the permissions specified to create it are denied.

I have three Linux machines, all built with the RHEL 4 distro, using gcc -lrt to link and have the same user id & group id set.
(All three machines are from different vendors, not that the HW probably matters?).

I can create semaphores on two of the machines but not on the third. I am using the same code (NFS mounted machines). What could be set different on the machines that would cause the EACCES (permission denied) error on only one of them???Where/what exactly am I being denied permission to?

Here is my crude code:

** seminit.c -- sets up a POSIX semaphore

#include <sys/stat.h>
#include <sys/sem.h>
#include <stdio.h>
#include <stdlib.h>
#include <semaphore.h>
#include <errno.h>
#include <fcntl.h>

int main (int argc, char *argv[])
sem_t *mySem;

mySem=sem_open("/name1", O_CREAT | O_EXCL, 0666, 2);

if (mySem == SEM_FAILED)
/* Check the error value */

if (errno == EACCES)
/* Permission is denied */
printf("Error: EACCESS Permission denied\n");
/* Show the other error */
printf("Some other error");
/* return; */
/* Process created the semaphore */
int a1;
printf("Sample data written\n");
sem_getvalue(mySem, &a1);
printf("Value of mySem=%d \n", a1);
** End seminit.c
Old 09-28-2006, 07:45 PM   #2
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
Are you certain that the named semaphore does not somehow already exist?

Anyhow, the Posix standard lists two possibilities for EACCES:
  • Valid name specified but oflag permissions are denied, or...
  • the semaphore name specified does not exist and permission to create the named semaphore is denied.
"What makes the third system different from the other two?" Or, what makes you different from the point-of-view of the third system?
Old 09-28-2006, 08:16 PM   #3
LQ Newbie
Registered: Sep 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for your help. Yeah, positive it didn't already exist. I tried using all different names and I had never created semaphores before.

This morning I found the solution to the problem... in a Unix forum respnse from 1997!

From what I now understand, POSIX semaphores are created in shared memory. So you need to make sure that users have rw permissions to /dev/shm for the semaphores to be created.

Then, as a handy option, put the following line in your fstab file to mount tmpfs:

none /dev/shm tmpfs defaults 0 0

So that when your machine is rebooted, the permissions are set right from the start.

That was the difference between my machines. Two of the three had /dev/shm set to drwxrwxrwx and the machine that would not allow creation of semaphores had it set to drwxr_xr_x.

Thanks to all those who may have looked into this problem.


Last edited by Mish; 09-28-2006 at 08:20 PM.


posix, semaphores

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ln: creating symbolic link `/dev/dvd' to `/dev/hdc': Permission denied qazwsx27 Fedora 3 06-14-2005 02:09 PM
Posix file based process shared semaphores dragonman Programming 9 05-25-2005 04:44 PM
POSIX semaphores acting strangely spuzzzzzzz Programming 0 10-18-2004 09:10 PM
permission denied error endezeichen Linux - General 5 12-20-2003 06:59 PM
POSIX File-based Semaphores dragonman Linux - Newbie 1 11-17-2002 10:51 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:55 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration