Hi…QNX6 lovers…
I try to create share memory and then copy the certain structure of variable using memcpy(). Unfortunately, my program terminate when calling memcpy() and apear output as below:
size of abc :16
Bus error (core dumped)
The codes are:
#include <stdio.h>
#include <fcntl.h> /for shm_open()/
#include <sys/mman.h>/for mmap()/
#include <string.h>
struct test {
int n;
bool flag;
};
static test abc[] = { {99,true},{55,false}};
int main(){
int fd;
test* lptest;
fd = shm_open(“test”,O_RDONLY|O_CREAT , 0666);
ftruncate(fd,sizeof(abc));
lptest = (test*)mmap(NULL,sizeof(abc),PROT_READ,MAP_SHARED,fd,0);
printf(“size of abc : %d \n”, sizeof(abc));
memcpy(lptest,abc,sizeof(abc)); /program terminate here!/
printf(“success to copy variable abc into share memory\n”);
close(fd);
return 0;
}
Why this happen? Any suggestion? Help me…
Regards
arms