#include #include #include #include #include #include #include #include #include #define SIZE 20 //syncro4.c int main(int argc, char **argv) { int fd, i, val, pid,*ptr; sem_t mutex; sem_t* pmutex; ptr = mmap(0, sizeof(int)*SIZE+sizeof(sem_t*), PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_SHARED, -1, 0); pmutex=(sem_t*)(ptr+sizeof(int)*SIZE); sem_init(pmutex,1,1); pid=fork(); if (pid == 0) { for (i = 0; i < SIZE; i++) { val=(*ptr)++; printf("figlio: %d\n", val); } exit(0); } else{ for (i = 0; i < SIZE; i++) { val=(*ptr)++; usleep(1e2); printf("padre: %d\n", val); } } wait(); return(0); }