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: Code:
shmid = shmget(skey, SEGMENT_SIZE, IPC_CREAT | 0666); i cant figure it out from the man pages....... thanks kin advance for your help... |
See this thread:
http://www.linuxquestions.org/questi...120#post747120 This is about semaphores and message queue's, but you can read about how create / connect to IPC stuff. Should work for shared mem as well, at least partly. To be able to tell if "the other" program is allready started you could create a (empty) file in /tmp and lock it. If one of your programs see the file is allready locked, you know another program is started, and you know that the IPC-stuff is already created and you should only connect. It maybe a good idea to also use the path of the tmp-lock file for generating the IPC key with ftok(). |
thanks...
i have another problem with the semaphore...
how exactly do i use the semaphore to signal the processes? i dont really get how am i suppose to use them, what should be the initial value of the semaphore.. how exactly do i implement a two communiaction ? when can i find a source code example..... |
Re: thanks...
Quote:
How do you know you need them? Quote:
Code:
sem_union.val = 1; Quote:
And/or download the code listings from wrox' book "Beginning Linux Programming" from: http://web.wrox.com/0764543733/2971.tar.gz (see chapter 12). |
All times are GMT -5. The time now is 12:58 PM. |