X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=prochand.tex;h=22da5c0194b660c71df60ba5a39403221ef5c9c3;hp=59eb4042a70957ff77e3324727dbccd860733f8b;hb=0697eab692e2d8e66f736e5be01648198aa83332;hpb=67a484c6ccfdb14cdd37678ca5df0db699801935 diff --git a/prochand.tex b/prochand.tex index 59eb404..22da5c0 100644 --- a/prochand.tex +++ b/prochand.tex @@ -208,25 +208,131 @@ ritorno della funzione fork figlio è zero; in questo modo il programma può identificare se viene eseguito dal padre o dal figlio. -Si noti come la funzione \fucn{fork} ritorni \textbf{due} volte: nel padre e -nel figlio. La sola differenza che si ha nei due processi è il valore di +\begin{figure}[!htb] + \footnotesize + \begin{lstlisting}{} +#include /* error definitions and routines */ +#include /* C standard library */ +#include /* unix standard library */ +#include /* standard I/O library */ +#include /* string functions */ + +/* Help printing routine */ +void usage(void); + +int main(int argc, char *argv[]) +{ +/* + * Variables definition + */ + int i; + int nchild; + pid_t pid; + + ... /* handling options */ + + /* There must be remaing parameters */ + if (optind == argc) { + usage(); + } + nchild = atoi(argv[optind]); + printf("Test for forking %d child\n", nchild); + /* loop to fork children */ + for (i=0; i