GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 15-Feb-2004, 08:33
socket socket is offline
New Member
 
Join Date: Feb 2004
Posts: 1
socket is on a distinguished road

shared memory and semaphores...


here's the deal...
i need two applications that i need to communicate through a shared memory segment...

lets say the user starts program A, i need it to create a shared memory segment and a semaphore,
when the user stats program B, i need it to attach itself to the segment and the semaphore.
i also need it to work the other way around, i cant tell which of the applications the users will start first.
i tried using a key for the semphore and the segment but i couldn't get it to work...

in both applications this is how i init the shared memory segment and the semaphore:
CPP / C++ / C Code:
	shmid = shmget(skey, SEGMENT_SIZE, IPC_CREAT | 0666);
	buffer = (char *) shmat(shmid, NULL, 0);

	semid = semget(skey,1,IPC_CREAT | 0666);
	semctl(semid, 0, SETALL, 0);


who do i set the properties that will create a segment if there isnt an segment exist with the key, if the segment exists i want to get the segment id so i could attach to it, same goes for the semaphore...
i cant figure it out from the man pages.......

thanks in advance for your help...
Last edited by dsmith : 15-Feb-2004 at 09:26. Reason: Added syntax highlighting
  #2  
Old 15-Feb-2004, 09:54
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hello socket. Quick note, gidforums has special codes for C syntax highlighting, if you use [c] and [/c], it will give you purdy highlighed code

I've never used shared app memory like this so I am grasping a little, but have you tried something like this: ***WARNING: UNCOMPILED CODE***
CPP / C++ / C Code:
if( (shmid = shmget(skey, SEGMENT_SIZE, IPC_CREAT | IPC_EXCL | 0666) ) == -1)
		if(errno == EEXSIT)
			shmid = shmget(skey, SEGMENT_SIZE, 0666);
This should check to see if the shared memory segment exists.

I haven't looked at the semaphore yet, but you can probably do something similar.

Sorry, I can't be of more help.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 1) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:19.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.