Cannot share memory (mmap)

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

Translate This Thread From English to

Threaded View
Hi,

I have serious problems sharing memory in my embedded Linux
application. I have looked up the Linux documentation, found some code
snippets and in addition used it for years in Windows but it will not
initialze here. Here is my condensed code:

int init_mmap(void)
{
  unsigned char result;
  int fd;

  fd=fopen("shared_mem.dat", "a+");
  shared_mem_prt=mmap(0, 1024, PROT_READ+PROT_WRITE, MAP_SHARED, fd,
0);

  result=0;
  return result;
}

The file already exists, has the correct size and does open. The
problem is that the mmap always return -1 which means a failure and
errno return subsequently 9. I have tried various other open modes and
shar modes but each time with the same result.

Can sombody please tell me what I am doing wrong?

I need this to communicate between two different applications. Is
shared memory the best way to do it or are there other ways in Linux?
(Sorry but my background is windows)

Thanks,

Jens.


Re: Cannot share memory (mmap)
Quoted text here. Click to load it

What exactly do you want to do ?



Re: Cannot share memory (mmap)
Quoted text here. Click to load it

What is your operating system ? If it is uClinux, it seems dosen't support
PROT_WRITE in MAP_SHARED options.

Re: Cannot share memory (mmap)

Quoted text here. Click to load it


As I recall, some architectures also require PROT_EXEC with PROT_WRITE due
to hardware limitations.

Site Timeline