#include #include #include #include #include #include #include //mmap-9-srv.c int main (int argc, char *argv[]) { const char* shm_name = "mymem"; const int SIZE = 4096; const char * message[] = {"Questo ","รจ un ","esempio di ","shared ","memory","\n"}; int i, fd; void * ptr; fd = shm_open(shm_name, O_CREAT | O_RDWR, 0666); if(fd==1){ printf("errore in shm_open\n"); exit(1); } ftruncate(fd, sizeof(message)); ptr = mmap(0, SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { printf("errore in mmap\n"); exit(1); } /* scrive la stringa in memoria */ for (i = 0; i < strlen(*message); ++i) { sprintf(ptr, "%s", message[i]); ptr += strlen(message[i]); } munmap(ptr, SIZE); return 0; }