X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=system.tex;h=4d980b22464cad62524effaebccb781dc9bd7778;hp=924935adb4daad23f90cf8760dc8c3515d56e645;hb=cf60963212306540ce7485ed7c86405e143a3352;hpb=758b135b7f04cdcebc4fe2726dc540cb24d116ba diff --git a/system.tex b/system.tex index 924935a..4d980b2 100644 --- a/system.tex +++ b/system.tex @@ -157,7 +157,7 @@ file, riportate in \tabref{tab:sys_file_macro}). \begin{table}[htb] \centering \footnotesize - \begin{tabular}[c]{|l|r|p{8cm}|} + \begin{tabular}[c]{|l|r|p{7cm}|} \hline \textbf{Costante}&\textbf{Valore}&\textbf{Significato}\\ \hline @@ -201,7 +201,7 @@ riportati in \tabref{tab:sys_posix1_general}. \begin{table}[htb] \centering \footnotesize - \begin{tabular}[c]{|l|r|p{8cm}|} + \begin{tabular}[c]{|l|r|p{7cm}|} \hline \textbf{Costante}&\textbf{Valore}&\textbf{Significato}\\ \hline @@ -365,22 +365,7 @@ sostituendolo a \code{\_POSIX\_} per le macro definite dagli gli altri due. In generale si dovrebbe fare uso di \func{sysconf} solo quando la relativa macro non è definita, quindi con un codice analogo al seguente: -%\footnotesize -\begin{lstlisting}[labelstep=0,frame=,indent=1cm]{} -get_child_max(void) -{ -#ifdef CHILD_MAX - return CHILD_MAX; -#else - int val = sysconf(_SC_CHILD_MAX); - if (val < 0) { - perror("fatal error"); - exit(-1); - } - return val; -} -\end{lstlisting} -%\normalsize +\includecodesnip{listati/get_child_max.c} ma in realtà in Linux queste macro sono comunque definite, indicando però un limite generico. Per questo motivo è sempre meglio usare i valori restituiti da \func{sysconf}. @@ -521,18 +506,7 @@ solo definendo \macro{\_GNU\_SOURCE}. \begin{figure}[!htb] \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct utsname { - char sysname[]; - char nodename[]; - char release[]; - char version[]; - char machine[]; -#ifdef _GNU_SOURCE - char domainname[]; -#endif -}; - \end{lstlisting} + \includestruct{listati/ustname.h} \end{minipage} \normalsize \caption{La struttura \structd{utsname}.} @@ -896,20 +870,7 @@ genere \begin{figure}[!htb] \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct statfs { - long f_type; /* tipo di filesystem */ - long f_bsize; /* dimensione ottimale dei blocchi di I/O */ - long f_blocks; /* blocchi totali nel filesystem */ - long f_bfree; /* blocchi liberi nel filesystem */ - long f_bavail; /* blocchi liberi agli utenti normali */ - long f_files; /* inode totali nel filesystem */ - long f_ffree; /* inode liberi nel filesystem */ - fsid_t f_fsid; /* filesystem id */ - long f_namelen; /* lunghezza massima dei nomi dei file */ - long f_spare[6]; /* riservati per uso futuro */ -}; -\end{lstlisting} + \includestruct{listati/statfs.h} \end{minipage} \normalsize \caption{La struttura \structd{statfs}.} @@ -983,17 +944,7 @@ il significato dei vari campi. \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct passwd { - char *pw_name; /* user name */ - char *pw_passwd; /* user password */ - uid_t pw_uid; /* user id */ - gid_t pw_gid; /* group id */ - char *pw_gecos; /* real name */ - char *pw_dir; /* home directory */ - char *pw_shell; /* shell program */ -}; - \end{lstlisting} + \includestruct{listati/passwd.h} \end{minipage} \normalsize \caption{La struttura \structd{passwd} contenente le informazioni relative ad @@ -1070,14 +1021,7 @@ in questo caso le informazioni vengono restituite in una struttura di tipo \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct group { - char *gr_name; /* group name */ - char *gr_passwd; /* group password */ - gid_t gr_gid; /* group id */ - char **gr_mem; /* group members */ -}; - \end{lstlisting} + \includestruct{listati/group.h} \end{minipage} \normalsize \caption{La struttura \structd{group} contenente le informazioni relative ad @@ -1206,6 +1150,18 @@ standard \const{\_PATH\_UTMP} (che corrispondenti ai file \file{/var/run/utmp} e \file{/var/log/wtmp} visti in precedenza. +\begin{figure}[!htb] + \footnotesize + \centering + \begin{minipage}[c]{15cm} + \includestruct{listati/utmp.h} + \end{minipage} + \normalsize + \caption{La struttura \structd{utmp} contenente le informazioni di una voce + del database di \textit{accounting}.} + \label{fig:sys_utmp_struct} +\end{figure} + Una volta aperto il file si può eseguire una scansione leggendo o scrivendo una voce con le funzioni \funcd{getutent}, \funcd{getutid}, \funcd{getutline} e \funcd{pututline}, i cui prototipi sono: @@ -1230,39 +1186,11 @@ e \funcd{pututline}, i cui prototipi sono: \end{functions} Tutte queste funzioni fanno riferimento ad una struttura di tipo \struct{utmp}, -la cui definizione in Linux è riportata in \secref{fig:sys_utmp_struct}. Le +la cui definizione in Linux è riportata in \figref{fig:sys_utmp_struct}. Le prime tre funzioni servono per leggere una voce dal database; \func{getutent} legge semplicemente la prima voce disponibile; le altre due permettono di eseguire una ricerca. -\begin{figure}[!htb] - \footnotesize - \centering - \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct utmp -{ - short int ut_type; /* Type of login. */ - pid_t ut_pid; /* Process ID of login process. */ - char ut_line[UT_LINESIZE]; /* Devicename. */ - char ut_id[4]; /* Inittab ID. */ - char ut_user[UT_NAMESIZE]; /* Username. */ - char ut_host[UT_HOSTSIZE]; /* Hostname for remote login. */ - struct exit_status ut_exit; /* Exit status of a process marked - as DEAD_PROCESS. */ - long int ut_session; /* Session ID, used for windowing. */ - struct timeval ut_tv; /* Time entry was made. */ - int32_t ut_addr_v6[4]; /* Internet address of remote host. */ - char __unused[20]; /* Reserved for future use. */ -}; - \end{lstlisting} - \end{minipage} - \normalsize - \caption{La struttura \structd{utmp} contenente le informazioni di una voce - del database di \textit{accounting}.} - \label{fig:sys_utmp_struct} -\end{figure} - Con \func{getutid} si può cercare una voce specifica, a seconda del valore del campo \var{ut\_type} dell'argomento \param{ut}. Questo può assumere i valori riportati in \tabref{tab:sys_ut_type}, quando assume i valori @@ -1377,26 +1305,7 @@ di tipo \struct{rusage}, la cui definizione (che si trova in \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct rusage { - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ - long ru_maxrss; /* maximum resident set size */ - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims */ - long ru_majflt; /* page faults */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; ; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary context switches */ -}; - \end{lstlisting} + \includestruct{listati/rusage.h} \end{minipage} \normalsize \caption{La struttura \structd{rusage} per la lettura delle informazioni dei @@ -1469,23 +1378,6 @@ struttura \struct{rlimit}, la cui definizione \figref{fig:sys_rlimit_struct}, ed i cui campi corrispondono appunto a limite corrente e limite massimo. -\begin{figure}[!htb] - \footnotesize - \centering - \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct rlimit { - rlim_t rlim_cur; - rlim_t rlim_max; -}; - \end{lstlisting} - \end{minipage} - \normalsize - \caption{La struttura \structd{rlimit} per impostare i limiti di utilizzo - delle risorse usate da un processo.} - \label{fig:sys_rlimit_struct} -\end{figure} - In genere il superamento di un limite comporta o l'emissione di un segnale o il fallimento della system call che lo ha provocato; per permettere di leggere e di impostare i limiti di utilizzo delle risorse da parte di un processo @@ -1514,6 +1406,20 @@ prototipi sono: ed \errval{EFAULT}.} \end{functions} +\begin{figure}[!htb] + \footnotesize + \centering + \begin{minipage}[c]{15cm} + \includestruct{listati/rlimit.h} + \end{minipage} + \normalsize + \caption{La struttura \structd{rlimit} per impostare i limiti di utilizzo + delle risorse usate da un processo.} + \label{fig:sys_rlimit_struct} +\end{figure} + + + Entrambe le funzioni permettono di specificare, attraverso l'argomento \param{resource}, su quale risorsa si vuole operare: i possibili valori di questo argomento sono elencati in \secref{tab:sys_rlimit_values}. L'acceso @@ -1578,13 +1484,13 @@ poi effettuato attraverso la struttura \struct{rlimit} puntata da evitare la creazione di \file{core} file (al proposito si veda \secref{sec:sig_prog_error}).} -Nello specificare un limite, oltre a dei valori specifici, si può anche usare -la costante \const{RLIM\_INFINITY} che permette di sbloccare l'uso di una -risorsa; ma si ricordi che solo un processo con i privilegi di amministratore -può innalzare un limite al di sopra del valore corrente del limite massimo. Si -tenga conto infine che tutti i limiti vengono ereditati dal processo padre -attraverso una \func{fork} (vedi \secref{sec:proc_fork}) e mantenuti per gli -altri programmi eseguiti attraverso una \func{exec} (vedi +Nello specificare un limite, oltre a fornire dei valori specifici, si può +anche usare la costante \const{RLIM\_INFINITY} che permette di sbloccare l'uso +di una risorsa; ma si ricordi che solo un processo con i privilegi di +amministratore può innalzare un limite al di sopra del valore corrente del +limite massimo. Si tenga conto infine che tutti i limiti vengono ereditati dal +processo padre attraverso una \func{fork} (vedi \secref{sec:proc_fork}) e +mantenuti per gli altri programmi eseguiti attraverso una \func{exec} (vedi \secref{sec:proc_exec}). @@ -1808,14 +1714,7 @@ struttura di tipo \struct{tms}, la cui definizione \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct tms { - clock_t tms_utime; /* user time */ - clock_t tms_stime; /* system time */ - clock_t tms_cutime; /* user time of children */ - clock_t tms_cstime; /* system time of children */ -}; - \end{lstlisting} + \includestruct{listati/tms.h} \end{minipage} \normalsize \caption{La struttura \structd{tms} dei tempi di processore associati a un @@ -1908,17 +1807,7 @@ nanosecondo.\footnote{la precisione \begin{figure}[!htb] \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct timeval -{ - long tv_sec; /* seconds */ - long tv_usec; /* microseconds */ -}; -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* nanoseconds */ -}; - \end{lstlisting} + \includestruct{listati/timeval.h} \end{minipage} \normalsize \caption{Le strutture \structd{timeval} e \structd{timespec} usate per una @@ -1971,29 +1860,7 @@ effettuato. \begin{figure}[!htb] \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct timex { - unsigned int modes; /* mode selector */ - long int offset; /* time offset (usec) */ - long int freq; /* frequency offset (scaled ppm) */ - long int maxerror; /* maximum error (usec) */ - long int esterror; /* estimated error (usec) */ - int status; /* clock command/status */ - long int constant; /* pll time constant */ - long int precision; /* clock precision (usec) (read only) */ - long int tolerance; /* clock frequency tolerance (ppm) (read only) */ - struct timeval time; /* (read only) */ - long int tick; /* (modified) usecs between clock ticks */ - long int ppsfreq; /* pps frequency (scaled ppm) (ro) */ - long int jitter; /* pps jitter (us) (ro) */ - int shift; /* interval duration (s) (shift) (ro) */ - long int stabil; /* pps stability (scaled ppm) (ro) */ - long int jitcnt; /* jitter limit exceeded (ro) */ - long int calcnt; /* calibration intervals (ro) */ - long int errcnt; /* calibration errors (ro) */ - long int stbcnt; /* stability limit exceeded (ro) */ -}; - \end{lstlisting} + \includestruct{listati/timex.h} \end{minipage} \normalsize \caption{La struttura \structd{timex} per il controllo dell'orologio di @@ -2128,31 +1995,6 @@ stata introdotta una ulteriore rappresentazione, detta \textit{broken-down time}, che permette appunto di \textsl{suddividere} il \textit{calendar time} usuale in ore, minuti, secondi, ecc. -\begin{figure}[!htb] - \footnotesize \centering - \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -struct tm { - int tm_sec; /* seconds */ - int tm_min; /* minutes */ - int tm_hour; /* hours */ - int tm_mday; /* day of the month */ - int tm_mon; /* month */ - int tm_year; /* year */ - int tm_wday; /* day of the week */ - int tm_yday; /* day in the year */ - int tm_isdst; /* daylight saving time */ - long int tm_gmtoff; /* Seconds east of UTC. */ - const char *tm_zone; /* Timezone abbreviation. */ -}; - \end{lstlisting} - \end{minipage} - \normalsize - \caption{La struttura \structd{tm} per una rappresentazione del tempo in - termini di ora, minuti, secondi, ecc.} - \label{fig:sys_tm_struct} -\end{figure} - Questo viene effettuato attraverso una opportuna struttura \struct{tm}, la cui definizione è riportata in \figref{fig:sys_tm_struct}, ed è in genere questa struttura che si utilizza quando si deve specificare un tempo a partire dai @@ -2192,6 +2034,19 @@ tempo in una stringa contenente data ed ora, i loro prototipi sono: restituisce direttamente il valore o -1 in caso di errore.} \end{functions} +\begin{figure}[!htb] + \footnotesize \centering + \begin{minipage}[c]{15cm} + \includestruct{listati/tm.h} + \end{minipage} + \normalsize + \caption{La struttura \structd{tm} per una rappresentazione del tempo in + termini di ora, minuti, secondi, ecc.} + \label{fig:sys_tm_struct} +\end{figure} + + + Le prime due funzioni, \func{asctime} e \func{ctime} servono per poter stampare in forma leggibile un tempo; esse restituiscono il puntatore ad una stringa, allocata staticamente, nella forma: @@ -2242,11 +2097,7 @@ verr \footnotesize \centering \begin{minipage}[c]{15cm} - \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{} -extern char *tzname[2]; -extern long timezone; -extern int daylight; - \end{lstlisting} + \includestruct{listati/time_zone_var.c} \end{minipage} \normalsize \caption{Le variabili globali usate per la gestione delle \textit{time @@ -2460,36 +2311,18 @@ punti e da uno spazio, il messaggio Il messaggio può essere riportato anche usando altre variabili globali dichiarate in \file{errno.h}: -\begin{verbatim} - const char *sys_errlist[]; - int sys_nerr; -\end{verbatim} +\includecodesnip{listati/errlist.c} la prima contiene i puntatori alle stringhe di errore indicizzati da \var{errno}; la seconda esprime il valore più alto per un codice di errore, l'utilizzo di questa stringa è sostanzialmente equivalente a quello di \func{strerror}. \begin{figure}[!htb] - \footnotesize - \begin{lstlisting}{} - /* convert string to number */ - err = strtol(argv[optind], NULL, 10); - /* testing error condition on conversion */ - if (err==LONG_MIN) { - perror("Underflow on error code"); - return 1; - } else if (err==LONG_MIN) { - perror("Overflow on error code"); - return 1; - } - /* conversion is fine */ - if (message) { - printf("Error message for %d is %s\n", err, strerror(err)); - } - if (label) { - printf("Error label for %d is %s\n", err, err_code[err]); - } - \end{lstlisting} + \footnotesize \centering + \begin{minipage}[c]{15cm} + \includecodesample{listati/errcode_mess.c} + \end{minipage} + \normalsize \caption{Codice per la stampa del messaggio di errore standard.} \label{fig:sys_err_mess} \end{figure}