Shared memory

Dec 04, 2004 4 Replies

I have two application running on my embedded Linux system and I need to communicate between the two. I have done this very successfully in Windows by shared memory and I wonder if this is possible in Linux too.



Shared memory is handy here because one appliacation will be setting flags and values the other one can read at its convenience and vice versa.



Thanks,



Jens.


Search for "sys/shm.h" in google. You will find tutorials about it on the first 2 pages.

Here is a code from me:

There is a code example at the end.

Greetings

Ernst

// 0xFFFF bytes empfangsbuffer: #define SHM_BUFFSIZE 0xFFFF im_shm_requestid = shmget(im_ID_Readkey,SHM_BUFFSIZE,S_IRWXU | S_IRWXG | S_IRWXO); if (im_shm_requestid == -1) im_shm_requestid = shmget(im_ID_Readkey,SHM_BUFFSIZE,S_IRWXU | S_IRWXG | S_IRWXO | IPC_CREAT /*| IPC_EXCL*/); if (im_shm_requestid == -1) { SetError(fErrBus_open); return false; } // empfangsbuffer anbinden: pm_ReceiveBuffer = (SendReceiveBuffer *) shmat(im_shm_requestid,0,0); if (pm_ReceiveBuffer

Remember that there are two ways doing shared memory in Linux. You can do the System V style or the POSIX way.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required