Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Semaphore problem 1

Status
Not open for further replies.

thumpkidd9

Programmer
Mar 27, 2005
42
US
Hello,

I am having a problem with my semaphores. After using semget(), it always returns a -1. I've read about different ways to initialize it but I dont see what is wrong.

Code:
sid1=semget(IPC_PRIVATE,N,0666|IPC_CREAT);   
(sid1==-1)printf("Trouble with semget\n");

is it a syntax error?

Thanks..
 
yes sry, it got cut off and didn't realize. The correct statement reads

Code:
if(sid1==-1) printf("Trouble with semget\n")
 
.. and what does perror("semget"); tell you? Replace the printf() with perror().
 
If you replace the printf statement with
Code:
perror(0);
you'll get a better indication of what's wrong.
 
after replacing printf() with perror(0). I get the message "no space left on device
 
So, you're out of space then ! Better free some up!

Out of interest, what value does N have at the time of calling semget()?
 
N is equal to 4. It turns out that I have like 10 open semaphores on this machine. gonna delete them and try again.
 
... yeah, was just about to post a "try cleaning up the ipc memory" message to you! :)
 
Sounds like: A semaphore set has to be created but the system limit for the maximum number of semaphore sets (SEMMNI), or the system wide maximum number of semaphores (SEMMNS), would be exceeded.

So you can check those to make sure you know which one is exceeded.


Hammer,

Just so you know, we posted our perror replies at the same time, and when I said "better" in mine, I meant better than the printf, not better than your suggestion.
 
Yep that was it. semaphores and shared mem working now. Thanks guys.
 
@chipperMDW : no worries, I knew what you meant! :-D

@thumpkidd9: glad you got it going!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top