\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm ]{}
+ \begin{lstlisting}[stepnumber=0]{}%,frame=,indent=1cm ]{}
struct ipc_perm
{
key_t key; /* Key. */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct msqid_ds {
struct ipc_perm msg_perm; /* structure for operation permission */
time_t msg_stime; /* time of last msgsnd command */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct msgbuf {
long mtype; /* message type, must be > 0 */
char mtext[LENGTH]; /* message data */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permission struct */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct sem {
short sempid; /* pid of last operation */
ushort semval; /* current value */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
union semun {
int val; /* value for SETVAL */
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct sembuf
{
unsigned short int sem_num; /* semaphore number */
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct shmid_ds {
struct ipc_perm shm_perm; /* operation perms */
int shm_segsz; /* size of segment (bytes) */
Benedyczak,\footnote{i patch al kernel e la relativa libreria possono essere
trovati su
\href{http://www.mat.uni.torun.pl/~wrona/posix_ipc}
-{http://www.mat.uni.torun.pl/\~{}wrona/posix\_ipc}.}.
+{http://www.mat.uni.torun.pl/\tild{}wrona/posix\_ipc}.}.
In generale, come le corrispettive del SysV IPC, le code di messaggi sono poco
usate, dato che i socket\index{socket}, nei casi in cui sono sufficienti, sono
più comodi, e che in casi più complessi la comunicazione può essere gestita
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct mq_attr {
long mq_flags; /* message queue flags */
long mq_maxmsg; /* maximum number of messages */
solo con le rispettive chiamate a \func{close} e \func{munmap}. Una volta
eseguita questa funzione però, qualora si richieda l'apertura di un segmento
con lo stesso nome, la chiamata a \func{shm\_open} fallirà, a meno di non aver
-usato \const{O\_CREAT}, nel qual caso comunque si otterrà il riferimento ad un
-segmento distinto dal precedente.
+usato \const{O\_CREAT}, in quest'ultimo caso comunque si otterrà un file
+descriptor che fa riferimento ad un segmento distinto da eventuali precedenti.
\begin{figure}[!htb]
\footnotesize \centering
/* Function RemoveShm: Remove a POSIX shared memory segment */
int RemoveShm(char * shm_name)
{
- shm_unlink(shm_name);
- return 0;
+ return shm_unlink(shm_name);
}
\end{lstlisting}
\end{minipage}
\label{fig:ipc_posix_shmmem}
\end{figure}
-Come esempio di queste funzioni vediamo come è possibile riscrivere con esse
-funzioni analoghe a quelle viste in \secref{fig:ipc_sysv_shm_func}; il codice,
-riportato in \figref{fig:ipc_posix_shmmem}, è sempre contenuto nel file
-\file{SharedMem.c} dei sorgenti allegati.
+Come esempio per l'uso di queste funzioni vediamo come è possibile riscrivere
+una interfaccia semplificata analoga a quella vista in
+\secref{fig:ipc_sysv_shm_func} per la memoria condivisa in stile SysV. Il
+codice, riportato in \figref{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
+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
nullo in caso di errore, o l'indirizzo (\texttt{\small 39}) dello stesso in
caso di successo.
-La terza funzione (\texttt{\small 40--46}) è \func{FindShm}, e serve a
+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 45}) in questo caso è chiamare \func{shm\_unlink}.
+fare (\texttt{\small 44}) in questo caso è chiamare \func{shm\_unlink},
+retituendo al chiamante il valore di ritorno.