Hi every one,
I need to create 8k bytes of shared memory area so what I have done is I am created a shared memory area as follows
Unsigned int *addr;
fd = shm_open( “/root/shmem1”, O_RDWR | O_CREAT, 0777 );
if( fd == -1 )
{
fprintf( stderr, “Open failed:%s\n”, strerror( errno ) );
return EXIT_FAILURE;
}
/* Set the memory object’s sizeas 8k*/
x= ftruncate( fd, 8192);
/here x value what I am getting is 0/
if( x == -1 )
{
fprintf( stderr, “ftruncate: %s\n”,strerror( errno ) );
return EXIT_FAILURE;
}
/* Map the memory object*/
addr = mmap(0,4, PROT_READ | PROT_WRITE , MAP_SHARED, fd, 0 );
if( addr == MAP_FAILED )
{
fprintf( stderr, “mmap failed: %s\n”, strerror( errno ) );
return EXIT_FAILURE;
}
And I am writing into shared memory as follows
int Write_To_Shared_Memory(int data, int location)
{
addr[location]=data;
return 0;
}
What my problem is when the location is >1023 then I am getting ‘memory fault error message’. Can any one please tell me where I am doing wrong and why this is happening