Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
if (mySem == SEM_FAILED)
{
/* Check the error value */
if (errno == EACCES)
{
/* Permission is denied */
printf("Error: EACCESS Permission denied\n");
}
else
{
/* Show the other error */
printf("Some other error");
/* return; */
}
}
else
{
/* Process created the semaphore */
int a1;
sem_wait(mySem);
printf("Sample data written\n");
sem_getvalue(mySem, &a1);
printf("Value of mySem=%d \n", a1);
sem_unlink("/name1");
sem_close(mySem);
exit(0);
}
}
/*
** End seminit.c
*/
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.