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.
I am using "sem_getcount" to get the semaphore count. But the gcc compiler is not recognizing this. I am using Linux version 2.6.9-22.EL gcc version 3.4.4 20050721 (Red Hat 3.4.4-2)).
Can anyone please tell me how to get the semaphore count??
I'm not sure what exactly you are looking for but you can look at "sysctl kernel.sem". This page has some info on interpreting the parameters. See also the sysctl(2) man page for doing it via syscalls within a C program.
Thanks for the reply.
Let me tell you What i am doing. In my C code, inside a blocking read call i waiting for the semaphore based on its count. So i will wait until some one releases the semaphore and the same i am checking through the sem_getcount().
So the problem that i am facing is "sem_getcount" not compilable. Is there any other way to get the semaphore count ???
OK, so you don't actually need to know the number of semaphores available on your system, you just need to know the value of a particular one. I totally misread you, which is why it's good to be specific when asking a question so people have some idea what you want.
In any case, I have not written semaphore code in a looong time but I think you can do what you want using semctl with the GETVAL cmd argument. Please see "man semctl" for more details. Note that this is if you're using the System V style semaphore API. If you're using POSIX semaphores the correct function is sem_getvalue (the description is in the man page for sem_init).based on the fact you were looking for sem_getcount (note the underscore), I'm guessing you're using POSIX semaphores and so sem_getvalue is the function you seek.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.