Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 11-25-2005, 12:49 PM   #1
LQ Newbie
Registered: Nov 2005
Posts: 1

Rep: Reputation: 0
shared memory between two processes

I want to be able to share memory between two processes. The background is that I have a framegrabber which locks a region of memory (containing multiple camera frames) and returns pointers to individual frames when a new frame is ready. These indivdual frames must be available to two seperate processes. I currently can't see any way of coercing shmget or shmat to allow me to use memory which I or the framegrabber specifies. For example, I've tried to do an shmget / shmat on a pointer to an array and the call to shmat fails. Is there any solution... I'm sure there must be some way of sharing memory between two processes where the location of the memory is known in advance?

Thanks for any suggestion,
Old 11-25-2005, 02:25 PM   #2
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
yes you can do shared memory (you have to do the syncronization yourself !)
first process allocates the memory using shget
this would create a new segment available to same user id or provide access by another process
int segment_id = shmget(shm_key, getpagesize(), IPC_CREAT | S_IRUSER | S_IWUSER);
then you attach the shared segment to a certain address space using shmat() with segment_id
returned from shmget like
char *shared_mem = (char*) shmat (segment_id, (void*) 0x5000000, 0);
detatch is
dealocate is
shmctl (segment_id, IPC_RMID, 0);

you can get info like
struct shmid_ds shmbuffer;
shmctl(segment_id, IPC_STAT, &shmbuffer);
int segment_size = shmbuffer.shm_segsz;

the first value passed to shget is the key other processes can use as an identifier to gain acess
if you need to garantee a new segment use the macro IPC_PRIVATE for the key


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
is shared memory expandable in memory size? Thinking Programming 4 08-16-2005 09:57 AM
how 2 c the memory used by processes imppayel Linux - General 3 12-08-2004 07:40 AM
sharing memory between processes spuzzzzzzz Programming 2 10-13-2004 07:18 AM
Listing processes by memory usage? Seventh Linux - Newbie 3 06-17-2004 10:05 AM
Memory And Processes smartes Linux - General 5 01-07-2003 02:02 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:43 PM.

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