+Come esempio per l'uso di queste funzioni vediamo come è possibile riscrivere
+una interfaccia semplificata analoga a quella vista in
+fig.~\ref{fig:ipc_sysv_shm_func} per la memoria condivisa in stile SysV. Il
+codice, riportato in fig.~\ref{fig:ipc_posix_shmmem}, è sempre contenuto nel
+file \file{SharedMem.c} dei sorgenti allegati.
+
+La prima funzione (\texttt{\small 1--24}) è \func{CreateShm} che, dato un nome
+nell'argomento \var{name} crea un nuovo segmento di memoria condivisa,
+accessibile in lettura e scrittura, e ne restituisce l'indirizzo. Anzitutto si
+definiscono (\texttt{\small 8}) i flag per la successiva (\texttt{\small 9})
+chiamata a \func{shm\_open}, che apre il segmento in lettura e scrittura
+(creandolo se non esiste, ed uscendo in caso contrario) assegnandogli sul
+filesystem i permessi specificati dall'argomento \var{perm}. In caso di errore
+(\texttt{\small 10--12}) si restituisce un puntatore nullo, altrimenti si
+prosegue impostando (\texttt{\small 14}) la dimensione del segmento con
+\func{ftruncate}. Di nuovo (\texttt{\small 15--16}) si esce immediatamente
+restituendo un puntatore nullo in caso di errore. Poi si passa (\texttt{\small
+ 18}) a mappare in memoria il segmento con \func{mmap} specificando dei
+diritti di accesso corrispondenti alla modalità di apertura. Di nuovo si
+restituisce (\texttt{\small 19--21}) un puntatore nullo in caso di errore,
+altrimenti si inizializza (\texttt{\small 22}) il contenuto del segmento al
+valore specificato dall'argomento \var{fill} con \func{memset}, e se ne
+restituisce (\texttt{\small 23}) l'indirizzo.
+
+La seconda funzione (\texttt{\small 25--40}) è \func{FindShm} che trova un
+segmento di memoria condiviso già esistente, restituendone l'indirizzo. In
+questo caso si apre (\texttt{\small 31}) il segmento con \func{shm\_open}
+richiedendo che il segmento sia già esistente, in caso di errore
+(\texttt{\small 31--33}) si ritorna immediatamente un puntatore nullo.
+Ottenuto il file descriptor del segmento lo si mappa (\texttt{\small 35}) in
+memoria con \func{mmap}, restituendo (\texttt{\small 36--38}) un puntatore
+nullo in caso di errore, o l'indirizzo (\texttt{\small 39}) dello stesso in
+caso di successo.
+
+La terza funzione (\texttt{\small 40--45}) è \func{RemoveShm}, e serve a
+cancellare un segmento di memoria condivisa. Dato che al contrario di quanto
+avveniva con i segmenti del SysV IPC gli oggetti allocati nel kernel vengono
+rilasciati automaticamente quando nessuna li usa più, tutto quello che c'è da
+fare (\texttt{\small 44}) in questo caso è chiamare \func{shm\_unlink},
+restituendo al chiamante il valore di ritorno.
+
+
+% LocalWords: like fifo System POSIX RPC Calls Common Object Request Brocker
+% LocalWords: Architecture descriptor kernel unistd int filedes errno EMFILE
+% LocalWords: ENFILE EFAULT BUF sez fig fork Stevens siblings EOF read SIGPIPE
+% LocalWords: EPIPE shell CGI Gateway Interface HTML JPEG URL mime type gs dup
+% LocalWords: barcode PostScript race condition stream BarCodePage WriteMess
+% LocalWords: size PS switch wait popen pclose stdio const char command NULL
+% LocalWords: EINVAL cap fully buffered Ghostscript l'Encapsulated epstopsf of
+% LocalWords: PDF EPS lseek ESPIPE PPM Portable PixMap format pnmcrop PNG pnm
+% LocalWords: pnmmargin png BarCode inode filesystem l'inode mknod mkfifo RDWR
+% LocalWords: ENXIO deadlock client reinviate fortunes fortunefilename daemon
+% LocalWords: FortuneServer FortuneParse FortuneClient pid libgapil LD
+% LocalWords: PATH linker pathname ps tmp killall fortuned crash socket domain
+% LocalWords: socketpair BSD sys protocol sv EAFNOSUPPORT EPROTONOSUPPORT AF
+% LocalWords: EOPNOTSUPP SOCK SysV IPC Process Comunication ipc perm key exec
+% LocalWords: header ftok proj stat libc SunOS glibc XPG dell'inode number uid
+% LocalWords: cuid cgid gid tab MSG shift group umask seq MSGMNI SEMMNI SHMMNI
+% LocalWords: shmmni msgmni sem sysctl IPCMNI IPCTestId msgget EACCES EEXIST
+% LocalWords: CREAT EXCL EIDRM ENOENT ENOSPC ENOMEM novo proc MSGMAX msgmax ds
+% LocalWords: MSGMNB msgmnb linked list msqid msgid linux msg qnum lspid lrpid
+% LocalWords: rtime ctime qbytes first last cbytes msgctl semctl shmctl ioctl
+% LocalWords: cmd struct buf EPERM RMID msgsnd msgbuf msgp msgsz msgflg EAGAIN
+% LocalWords: NOWAIT EINTR mtype mtext long message sizeof LENGTH ts sleep BIG
+% LocalWords: msgrcv ssize msgtyp NOERROR EXCEPT ENOMSG multiplexing select ls
+% LocalWords: poll polling queue MQFortuneServer write init HandSIGTERM
+% LocalWords: MQFortuneClient mqfortuned mutex risorse' inter semaphore semget
+% LocalWords: nsems SEMMNS SEMMSL semid otime semval sempid semncnt semzcnt nr
+% LocalWords: SEMVMX SEMOPM semop SEMMNU SEMUME SEMAEM semnum union semun arg
+% LocalWords: ERANGE SETALL SETVAL GETALL array GETNCNT GETPID GETVAL GETZCNT
+% LocalWords: sembuf sops unsigned nsops UNDO flg nsop num undo pending semadj
+% LocalWords: sleeper scheduler running next semundo MutexCreate semunion lock
+% LocalWords: MutexFind wrapper MutexRead MutexLock MutexUnlock unlock locking
+% LocalWords: MutexRemove shmget SHMALL SHMMAX SHMMIN shmid shm segsz atime FD
+% LocalWords: dtime lpid cpid nattac shmall shmmax SHMLBA SHMSEG EOVERFLOW brk
+% LocalWords: memory shmat shmdt void shmaddr shmflg SVID RND RDONLY rounded
+% LocalWords: SIGSEGV nattch exit SharedMem ShmCreate memset fill ShmFind home
+% LocalWords: ShmRemove DirMonitor DirProp chdir GaPiL shmptr DirScan ipcs NFS
+% LocalWords: ComputeValues ReadMonitor touch SIGTERM dirmonitor unlink fcntl
+% LocalWords: LockFile UnlockFile CreateMutex FindMutex LockMutex SETLKW GETLK
+% LocalWords: UnlockMutex RemoveMutex ReadMutex UNLCK WRLCK RDLCK mapping MAP
+% LocalWords: SHARED ANONYMOUS thread patch names strace system call userid Di
+% LocalWords: groupid Michal Wronski Krzysztof Benedyczak wrona posix mqueue
+% LocalWords: lmqueue gcc mount mqd name oflag attr maxmsg msgsize receive ptr
+% LocalWords: send WRONLY NONBLOCK close mqdes EBADF getattr setattr mqstat
+% LocalWords: omqstat curmsgs flags timedsend len prio timespec abs EMSGSIZE
+% LocalWords: ETIMEDOUT timedreceive getaddr notify sigevent notification l'I
+% LocalWords: EBUSY sigev SIGNAL signo value sigval siginfo all'userid MESGQ
+% LocalWords: Konstantin Knizhnik futex tmpfs ramfs cache shared swap CONFIG
+% LocalWords: lrt blocks PAGECACHE TRUNC CLOEXEC mmap ftruncate munmap FindShm
+% LocalWords: CreateShm RemoveShm LIBRARY