Shared memory

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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.

Re: Shared memory
Quoted text here. Click to load it

Absolutely.

Re: Shared memory
Quoted text here. Click to load it
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 <= 0)
        {        
        SetError(fErrBus_connect);
                                                                        
        return false;
        }
            
   // 0xFFFF bytes sendebuffer:
    im_shm_sendid = shmget(im_ID_Writekey,SHM_BUFFSIZE,S_IRWXU | S_IRWXG |
S_IRWXO );
    if (im_shm_sendid == -1)
            im_shm_sendid = shmget(im_ID_Writekey,SHM_BUFFSIZE,S_IRWXU | S_IRWXG
| S_IRWXO | IPC_CREAT /*| IPC_EXCL*/);
    if (im_shm_sendid == -1)
        {
        SetError(fErrBus_open);
                                                                        
      return false;
      }
    // sendebuffer anbinden:
    pm_SendBuffer = (SendReceiveBuffer *) shmat(im_shm_sendid,0,0);
    if (pm_SendBuffer <= 0)
        {        
        SetError(fErrBus_connect);
                                                                        
        return false;
        }

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

Quoted text here. Click to load it


Re: Shared memory
You can use shared mem in linux, API such as mmap can give you a reference.


Quoted text here. Click to load it


Site Timeline