LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2008, 07:14 AM   #1
pumplove
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Rep: Reputation: 0
semop issue


Hi All,
Have written a sample program which uses shared memory and semaphores to protect those ...

typedef struct{

int a;
float b;
char c[10];

} locStr;

main(int ctr, char* arr[]){
int shmId, keyId ;
struct sembuf locSem;

locStr *locPtr = NULL;
locSem.sem_num = 0;
locSem.sem_op = -1;
locSem.sem_flg = IPC_NOWAIT;

shmId = shmget(666, sizeof(locStr), IPC_CREAT);
keyId = semget(atoi(arr[1]), 1, 0777|IPC_CREAT);
if(keyId == -1)
printf("MAAN %d and <%s>\n", keyId, strerror(errno));
else
printf("MAAN %d and <%s>\n", keyId, strerror(errno));

printf("The val of the sem is <%d>\n",semctl(keyId, 0, GETVAL));

if(semop(keyId, &locSem, 1) == -1)
printf("MAAN %d and <%s>\n", keyId, strerror(errno));



sleep(5);
locSem.sem_op = -1;
if(semop(keyId, &locSem, 1) == -1)
printf("MAAN %d and <%s>\n", keyId, strerror(errno));


if( shmId > 0)
{
locPtr = (locStr *)shmat(shmId,NULL,0);
}
else
printf("GONE 4 A TOSS\n");


semctl(keyId, 0 , IPC_RMID);


}


The first semop (in bold) operation always returns "Resource temporarily unavailable", though i have just created the semaphore ( i also check using a semctl call that the semapaphore is a 0) and am locking the sem by decreasing the value by 1.Please help

Last edited by pumplove; 01-21-2008 at 07:15 AM.
 
Old 01-22-2008, 02:21 AM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
This thread is better off in programming, and has been moved accordingly.
 
  


Reply



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
SuSE10.2 networking issue Inter. connect. issue LVSuSE Linux - Networking 3 08-31-2007 02:42 AM
Sendmail issue (did not issue MAIL/EXPNVRFY/ETRN ...) Blackout_08 Linux - Server 0 08-08-2007 01:10 PM
Slack 10.1 -- Mouse issue / X11 issue Pozican Linux - General 4 04-19-2005 03:44 AM
Having Issue w/ Truetype fonts - Mozilla Issue clove Linux - Software 4 02-18-2004 08:26 AM
semop returns -1 but errno is 0 DaveRob Programming 1 08-11-2003 05:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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