X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=prochand.tex;h=90da68176a6c4159f16cd0eb25900d6530d0008f;hb=2df3e366683f4df738d40a05b97f820fde1648d9;hp=59eb4042a70957ff77e3324727dbccd860733f8b;hpb=67a484c6ccfdb14cdd37678ca5df0db699801935;p=gapil.git diff --git a/prochand.tex b/prochand.tex index 59eb404..90da681 100644 --- a/prochand.tex +++ b/prochand.tex @@ -208,25 +208,132 @@ 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