processi.
Il kernel mantiene una tabella dei processi attivi, la cosiddetta
-\textit{process table}; per ciascun processo viene mantenuta una voce nella
-tabella dei processi costituita da una struttura \struct{task\_struct}, che
-contiene tutte le informazioni rilevanti per quel processo. Tutte le strutture
-usate a questo scopo sono dichiarate nell'header file \file{linux/sched.h}, ed
-uno schema semplificato, che riporta la struttura delle principali informazioni
-contenute nella \struct{task\_struct} (che in seguito incontreremo a più
-riprese), è mostrato in \figref{fig:proc_task_struct}.
+\textit{process table}; per ciascun processo viene mantenuta una voce,
+costituita da una struttura \struct{task\_struct}, nella tabella dei processi
+che contiene tutte le informazioni rilevanti per quel processo. Tutte le
+strutture usate a questo scopo sono dichiarate nell'header file
+\file{linux/sched.h}, ed uno schema semplificato, che riporta la struttura
+delle principali informazioni contenute nella \struct{task\_struct} (che in
+seguito incontreremo a più riprese), è mostrato in
+\figref{fig:proc_task_struct}.
\begin{figure}[htb]
\centering
\bodydesc{Entrambe le funzioni non riportano condizioni di errore.}
\end{functions}
\noindent esempi dell'uso di queste funzioni sono riportati in
-\figref{fig:proc_fork_code}, nel programma di esempio \file{ForkTest.c}.
+\figref{fig:proc_fork_code}, nel programma \file{ForkTest.c}.
Il fatto che il \acr{pid} sia un numero univoco per il sistema lo rende un
candidato per generare ulteriori indicatori associati al processo di cui
che non è il \acr{pid} di nessun processo.
\begin{figure}[!htb]
- \footnotesize
- \begin{lstlisting}{}
-#include <errno.h> /* error definitions and routines */
-#include <stdlib.h> /* C standard library */
-#include <unistd.h> /* unix standard library */
-#include <stdio.h> /* standard I/O library */
-#include <string.h> /* string functions */
-
-/* Help printing routine */
-void usage(void);
-
-int main(int argc, char *argv[])
-{
-/*
- * Variables definition
- */
- int nchild, i;
- pid_t pid;
- int wait_child = 0;
- int wait_parent = 0;
- int wait_end = 0;
- ... /* handling options */
- nchild = atoi(argv[optind]);
- printf("Test for forking %d child\n", nchild);
- /* loop to fork children */
- for (i=0; i<nchild; i++) {
- if ( (pid = fork()) < 0) {
- /* on error exit */
- printf("Error on %d child creation, %s\n", i+1, strerror(errno));
- exit(-1);
- }
- if (pid == 0) { /* child */
- printf("Child %d successfully executing\n", ++i);
- if (wait_child) sleep(wait_child);
- printf("Child %d, parent %d, exiting\n", i, getppid());
- exit(0);
- } else { /* parent */
- printf("Spawned %d child, pid %d \n", i+1, pid);
- if (wait_parent) sleep(wait_parent);
- printf("Go to next child \n");
- }
- }
- /* normal exit */
- if (wait_end) sleep(wait_end);
- return 0;
-}
- \end{lstlisting}
+ \footnotesize \centering
+ \begin{minipage}[c]{15cm}
+ \includecodesample{listati/ForkTest.c}
+ \end{minipage}
+ \normalsize
\caption{Esempio di codice per la creazione di nuovi processi.}
\label{fig:proc_fork_code}
\end{figure}
Nel secondo caso le stringhe degli argomenti sono passate alla funzione come
lista di puntatori, nella forma:
-\begin{lstlisting}[labelstep=0,frame=,indent=1cm]{}
- char *arg0, char *arg1, ..., char *argn, NULL
-\end{lstlisting}
+\includecodesnip{listati/char_list.c}
che deve essere terminata da un puntatore nullo. In entrambi i casi vale la
convenzione che il primo argomento (\var{arg0} o \var{argv[0]}) viene usato
per indicare il nome del file che contiene il programma che verrà eseguito.
\begin{figure}[!htb]
\footnotesize \centering
\begin{minipage}[c]{15cm}
- \begin{lstlisting}[labelstep=0]{}%,frame=,indent=1cm]{}
+ \begin{lstlisting}[stepnumber=0]{}
struct sched_param {
int sched_priority;
};