I'm using shared_memory using POSIX..
I've allocated 4KB, but i can use a lot more than 4KB... it gives me a segmentation fault when i write more than ~10350 characters into memory. which equals to ~10350 byte / 1024 = ~10KB ?
I believe that the operating system should guard the Memory for such a violation, but it allows me to ? Why ?
Producer Source-code which is used to put something into the shared-memory segment
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
int main(void)
{
const int size = 4096; //4kb
const char *name = "os";
const char *message = "Put more than 5000 chars it will work perfectly but less than 10350 or something like that";
int shm_fd;
void *ptr;
shm_fd = shm_open(name,O_CREAT | O_RDWR,0666);
ftruncate(shm_fd,size);// set the size to 4kb
ptr = mmap(0,size,PROT_WRITE | PROT_READ,MAP_SHARED,shm_fd,0);
sprintf(ptr,"%s",message);
ptr += strlen(message);
return 0;