Cannot share memory (mmap)

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.

Reply to
Jens
Loading thread data ...

What exactly do you want to do ?

Reply to
Helix

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

Reply to
brian

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

Reply to
Ed Skinner

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.