When trying to access newly created shared memory the program crashes.
For testing I have typed in a code example from QNX 4 Real-time Operating
System by Frank Kolnick ( page 272-273 if you have the text ) so it should
not be a coding problem.
shm_open, ltrunc, mmap all seem to work fine. Mmap always returns the same
pointer ( 0x40100000 ).
The program crashes when I try to access the shared memory ie trying to
write something to that memory location. Here is a code snippet with all
the error checking, includes etc removed.
main ( void )
{
int mem;
char *where;
mem = shm_open(“mem_test”, O_CREAT | O_RDWR, 0777);
ltrunc(mem, 4096, SEEK_SET );
where = mmap(0,4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem, 0);
strcpy(where,“original string”); // this is the line it crashes on
munmap( where, 4096 );
close (mem);
shm_unlink(where, 4096);
}
I have tried the cc, gcc and qcc and they all do the same thing.
Any help would be appreciated.
When trying to access newly created shared memory the program crashes.
For testing I have typed in a code example from QNX 4 Real-time Operating
System by Frank Kolnick ( page 272-273 if you have the text ) so it should
not be a coding problem.
shm_open, ltrunc, mmap all seem to work fine. Mmap always returns the same
pointer ( 0x40100000 ).
The program crashes when I try to access the shared memory ie trying to
write something to that memory location. Here is a code snippet with all
the error checking, includes etc removed.
main ( void )
{
int mem;
char *where;
mem = shm_open(“mem_test”, O_CREAT | O_RDWR, 0777);
ltrunc(mem, 4096, SEEK_SET );
where = mmap(0,4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem, 0);
strcpy(where,“original string”); // this is the line it crashes on
munmap( where, 4096 );
close (mem);
shm_unlink(where, 4096);
}
I have tried the cc, gcc and qcc and they all do the same thing.
Any help would be appreciated.
When trying to access newly created shared memory the program crashes.
For testing I have typed in a code example from QNX 4 Real-time Operating
System by Frank Kolnick ( page 272-273 if you have the text ) so it should
not be a coding problem.
shm_open, ltrunc, mmap all seem to work fine. Mmap always returns the
same
pointer ( 0x40100000 ).
The program crashes when I try to access the shared memory ie trying to
write something to that memory location.
That’s not what I got when I ran the sample. It crash
AFTER main, that would be in exit code of the C lib.
Here is a code snippet with all
the error checking, includes etc removed.
main ( void )
{
int mem;
char *where;
mem = shm_open(“mem_test”, O_CREAT | O_RDWR, 0777);
ltrunc(mem, 4096, SEEK_SET );
where = mmap(0,4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem, 0);
strcpy(where,“original string”); // this is the line it crashes on
munmap( where, 4096 );
close (mem);
this is what is causing the problem, the compilier should have spit out
warning (wrong prototypes). shm_unlink takes the name of the share mem as
argument.
I changed it to shm_unlink(“mem_test”) and the sample work fine.
shm_unlink(where, 4096); "
}
I have tried the cc, gcc and qcc and they all do the same thing.
Previously, Wenham wrote in qdn.public.qnx4.devtools:
When trying to access newly created shared memory the program crashes.
For testing I have typed in a code example from QNX 4 Real-time Operating
System by Frank Kolnick ( page 272-273 if you have the text ) so it should
not be a coding problem.
shm_open, ltrunc, mmap all seem to work fine. Mmap always returns the same
pointer ( 0x40100000 ).
The program crashes when I try to access the shared memory ie trying to
write something to that memory location. Here is a code snippet with all
the error checking, includes etc removed.
main ( void )
{
int mem;
char *where;
mem = shm_open(“mem_test”, O_CREAT | O_RDWR, 0777);
ltrunc(mem, 4096, SEEK_SET );
where = mmap(0,4096, PROT_READ | PROT_WRITE, MAP_SHARED, mem, 0);
strcpy(where,“original string”); // this is the line it crashes on
munmap( where, 4096 );
close (mem);
shm_unlink(where, 4096);
}
I have tried the cc, gcc and qcc and they all do the same thing.
Any help would be appreciated.
You should test the return code from shm_open, as it might have
failed.
You should test the return code from mmap, as it might have
failed.
Your mmap probably failed, returned NULL, and you passed NULL to
strcpy, which caused a segmentation fault. Are you running this
program as ROOT? You will need to.