Completate le aggiunte della GPL per i programmi
authorSimone Piccardi <piccardi@gnulinux.it>
Sun, 9 Sep 2001 22:45:34 +0000 (22:45 +0000)
committerSimone Piccardi <piccardi@gnulinux.it>
Sun, 9 Sep 2001 22:45:34 +0000 (22:45 +0000)
prochand.tex
sources/ElemDaytimeTCPClient.c
sources/ElemDaytimeTCPServer.c
sources/ElemEchoTCPClient.c
sources/ErrCode.c
sources/ForkTest.c
sources/Makefile
sources/SimpleEchoTCPClient.c
sources/SimpleEchoTCPServer.c
sources/SockRead.c
sources/SockWrite.c

index 8f8beaffd588c9f45d0654c6a40cde391548d823..41d7a348c2e7a9702ea2f4a97d2786cc41e66d1f 100644 (file)
@@ -278,20 +278,54 @@ numero di figli specificato a linea di comando; il codice completo, compresa
 la parte che gestisce le opzioni a riga di comando, è disponibile nel file
 \file{ForkTest.c}.
 
 la parte che gestisce le opzioni a riga di comando, è disponibile nel file
 \file{ForkTest.c}.
 
-Decifrato il numero di figli da creare il ciclo principale del programma
+Decifrato il numero di figli da creare, il ciclo principale del programma
 (\texttt{\small 28--40}) esegue in successione la creazione dei processi figli
 (\texttt{\small 28--40}) esegue in successione la creazione dei processi figli
-(\texttt{\small 29--31}) controllando il successo della chiamata a
-\func{fork}; ciascun figlio (\texttt{\small 29--31}) si limita a stampare il
+controllando il successo della chiamata a \func{fork} (\texttt{\small
+  29--31}); ciascun figlio (\texttt{\small 29--31}) si limita a stampare il
 suo numero di successione, attendere 2 secondi e scrivere un messaggio prima
 di uscire. Il processo padre invece (\texttt{\small 29--31}) stampa un
 suo numero di successione, attendere 2 secondi e scrivere un messaggio prima
 di uscire. Il processo padre invece (\texttt{\small 29--31}) stampa un
-messaggio di creazione e procede nell'esecuzione del ciclo.
-
-In generale\footnote{anche se nel kernel 2.4.x è stato introdotto un
+messaggio di creazione e procede nell'esecuzione del ciclo. Se eseguiamo il
+comando otterremo:
+\begin{verbatim}
+[piccardi@selidor sources]$ ./forktest 5
+Test for forking 5 child
+Spawned 1 child, pid 840 
+Child 1 successfully executing
+Child 2 successfully executing
+Spawned 2 child, pid 841 
+Spawned 3 child, pid 842 
+Child 3 successfully executing
+Spawned 4 child, pid 843 
+Child 4 successfully executing
+Child 5 successfully executing
+Spawned 5 child, pid 844 
+[piccardi@selidor sources]$ Child 2 exiting
+Child 1 exiting
+Child 4 exiting
+Child 3 exiting
+Child 5 exiting
+\end{verbatim}
+
+
+Come si vede non si può dire quale processo fra il padre ed il figlio venga
+eseguito per primo\footnote{anche se nel kernel 2.4.x era stato introdotto un
   meccanismo che metteva in esecuzione sempre il xxx per primo (TODO
   meccanismo che metteva in esecuzione sempre il xxx per primo (TODO
-  recuperare le informazioni esatte)} non si può dire quale processo fra il
-padre ed il figlio venga eseguito per primo dopo la chiamata a \func{fork},
-per cui se i due processi devono essere sincronizzati occorre ricorrere ad un
-qualche meccanismo di intercomunicazione.
+  recuperare le informazioni esatte)} dopo la chiamata a \func{fork}, nel caso
+mostrato sopra ad esempio si può notare come dopo la creazione il secondo ed
+il quinto figlio sia stato stati eseguiti per primi, mantre per gli altri
+figli è stato eseguito per primo il padre. In generale l'ordine di esecuzione
+dipenderà dalla situazione particolare in si trova la macchina al momento
+della chiamata, risultando del tutto impredicibile, per questo motivo se i due
+processi devono essere sincronizzati occorrerà ricorrere ad un opportuno
+meccanismo di intercomunicazione.
+
+Si ricordi inoltre che, essendo i segmenti di memoria utilizzati dai singoli
+processi completamente separati, le modifiche delle variabili nei processi
+figli (come l'incremento di \var{i} in \texttt{\small 33}) saranno effettive
+solo per essi, e non hanno alcun effetto sul valore che le stesse variabili
+hanno nel processo padre.
+
+
 
 
 \subsection{Le funzioni \texttt{wait} e  \texttt{waitpid}}
 
 
 \subsection{Le funzioni \texttt{wait} e  \texttt{waitpid}}
index d241f16d10b02ac914a954554c45bdef4ec0c064..d049b7d66b7c1c98b7c23bc5805091e7544995ce 100644 (file)
 /****************************************************************
  *
  * Program daytime: 
 /****************************************************************
  *
  * Program daytime: 
- * Simple TCP client for daytime service (port 13)
+ * Elementary TCP client for daytime service (port 13)
  *
  * Author: Simone Piccardi
  * Apr. 2001
  *
  * Usage: daytime -h give all info's
  *
  *
  * Author: Simone Piccardi
  * Apr. 2001
  *
  * Usage: daytime -h give all info's
  *
- * $Id: ElemDaytimeTCPClient.c,v 1.1 2001/09/09 17:39:15 piccardi Exp $ 
+ * $Id: ElemDaytimeTCPClient.c,v 1.2 2001/09/09 22:45:34 piccardi Exp $ 
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
index 057ce9787fb40b36e24e8cefa91ca8e50430ccb9..9ab656afb18ee8c2e7774d07930c7bdf4a49ff5b 100644 (file)
@@ -1,6 +1,6 @@
-/* ElemDaytimeTCPClient.c
+/* ElemDaytimeTCPServer.c
  * 
  * 
- * Copyright (C) 2000 Simone Piccardi
+ * Copyright (C) 2001 Simone Piccardi
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-//****************************************************************
+/****************************************************************
  *
  * Program daytimed: 
  * Elementary TCP server for daytime service (port 13)
  *
  * Program daytimed: 
  * Elementary TCP server for daytime service (port 13)
@@ -24,9 +24,9 @@
  * Author: Simone Piccardi
  * Apr. 2001
  *
  * Author: Simone Piccardi
  * Apr. 2001
  *
- * Usage: daytimed
+ * Usage: daytimed -h give all info
  *
  *
- * $Id: ElemDaytimeTCPServer.c,v 1.2 2001/09/09 17:39:15 piccardi Exp $ 
+ * $Id: ElemDaytimeTCPServer.c,v 1.3 2001/09/09 22:45:34 piccardi Exp $ 
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
index eafdc81d6388531fb4fa92a880ecff8bd3cc5170..57b8fa1e3a94bcee4018ac14ddb92cf3afee2444 100644 (file)
@@ -1,6 +1,24 @@
+/* ElemEchoTCPClient.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 /****************************************************************
  *
 /****************************************************************
  *
- * Program SimpleEchoTCPClient: 
+ * Program ElemEchoTCPClient.c
  * Simple TCP client for echo service (port 7)
  *
  * Author: Simone Piccardi
  * Simple TCP client for echo service (port 7)
  *
  * Author: Simone Piccardi
@@ -8,7 +26,7 @@
  *
  * Usage: echo -h give all info's
  *
  *
  * Usage: echo -h give all info's
  *
- * $Id: ElemEchoTCPClient.c,v 1.2 2001/06/20 22:03:37 piccardi Exp $
+ * $Id: ElemEchoTCPClient.c,v 1.3 2001/09/09 22:45:34 piccardi Exp $
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
index 58f5491669ebea90a4bff3d99290fd849ad44465..5106885503a25e7b86a5e1767e30901d2aa33f91 100644 (file)
@@ -1,3 +1,21 @@
+/* ErrCode.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 /****************************************************************
  *
  * Program ErrCode.c: 
 /****************************************************************
  *
  * Program ErrCode.c: 
@@ -8,7 +26,7 @@
  *
  * Usage: errcode -h give all info's
  *
  *
  * Usage: errcode -h give all info's
  *
- * $Id: ErrCode.c,v 1.1 2001/09/09 17:39:15 piccardi Exp $ 
+ * $Id: ErrCode.c,v 1.2 2001/09/09 22:45:34 piccardi Exp $ 
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
index da38629b41892b6be703821222303d4da4073576..09035d5a66b1583d05a41c166c1ae8754864f74f 100644 (file)
@@ -1,3 +1,21 @@
+/* ForkTest.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 /****************************************************************
  *
  * Program ForkTest.c: 
 /****************************************************************
  *
  * Program ForkTest.c: 
@@ -8,7 +26,7 @@
  *
  * Usage: forktest -h give all info's
  *
  *
  * Usage: forktest -h give all info's
  *
- * $Id: ForkTest.c,v 1.1 2001/09/09 17:39:15 piccardi Exp $
+ * $Id: ForkTest.c,v 1.2 2001/09/09 22:45:34 piccardi Exp $
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
@@ -69,15 +87,15 @@ int main(int argc, char *argv[])
     /* loop to fork children */
     for (i=0; i<nchild; i++) {
        if ( (pid = fork()) < 0) {
     /* loop to fork children */
     for (i=0; i<nchild; i++) {
        if ( (pid = fork()) < 0) {
-           printf("Error on %d child creation, %s\n", i, strerror(errno));
+           printf("Error on %d child creation, %s\n", i+1, strerror(errno));
        }
        if (pid == 0) {   /* child */
        }
        if (pid == 0) {   /* child */
-           printf("Child %d successfully executing\n", i++);
+           printf("Child %d successfully executing\n", ++i);
            sleep(2);
            printf("Child %d exiting\n", i);
            exit(0);
        } else {          /* parent */
            sleep(2);
            printf("Child %d exiting\n", i);
            exit(0);
        } else {          /* parent */
-           printf("Spawned %d child, pid %d \n", i, pid);
+           printf("Spawned %d child, pid %d \n", i+1, pid);
        }
     }
     /* normal exit */
        }
     }
     /* normal exit */
index c1976a795e2b77696bac040b2ffe9d88b01be287..64293b7229d4c45f266e6655a0e170c66742496e 100644 (file)
@@ -8,6 +8,8 @@ CFLADJ=-c
 
 OBJ = SockRead.o SockWrite.o
 
 
 OBJ = SockRead.o SockWrite.o
 
+all: forktest errcode echo echod daytimed iterdaytimed daytime
+
 forktest: ForkTest.c
        $(CC) $(CFLAGS) $^ -o $@
 
 forktest: ForkTest.c
        $(CC) $(CFLAGS) $^ -o $@
 
@@ -35,7 +37,7 @@ $(OBJ): wrappers.h
 
 .PHONY : clean
 clean:
 
 .PHONY : clean
 clean:
-       rm -f daytime iterdaytimed daytimed echod echo errcode
+       rm -f daytime iterdaytimed daytimed echod echo errcode forktest
        rm -f *~
        rm -f *.o
 
        rm -f *~
        rm -f *.o
 
index 31adf9fdabc7793ab906b6af25e8658f055cd854..5661f870a1e96c96593badfe43984e35fb1d9ebd 100644 (file)
@@ -1,6 +1,24 @@
+/* SimpleEchoTCPClient.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 /****************************************************************
  *
 /****************************************************************
  *
- * Program SimpleEchoTCPClient
+ * Program echo
  * Simple TCP client for echo service (port 7)
  *
  * Author: Simone Piccardi
  * Simple TCP client for echo service (port 7)
  *
  * Author: Simone Piccardi
@@ -8,7 +26,7 @@
  *
  * Usage: echo -h give all info's
  *
  *
  * Usage: echo -h give all info's
  *
- * $Id: SimpleEchoTCPClient.c,v 1.3 2001/06/17 21:58:46 piccardi Exp $
+ * $Id: SimpleEchoTCPClient.c,v 1.4 2001/09/09 22:45:34 piccardi Exp $
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
index 9611e365eb2856d3e75f9de0c019c80a8896a1d9..beda57480c9c9000681f2fc6dbbaf60f810145c9 100644 (file)
@@ -1,6 +1,24 @@
+/* SimpleEchoTCPServer.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 /****************************************************************
  *
 /****************************************************************
  *
- * Program echo_tcp_server.c
+ * Program echod
  * Elementary TCP server for echo service (port 7)
  *
  * Author: Simone Piccardi
  * Elementary TCP server for echo service (port 7)
  *
  * Author: Simone Piccardi
@@ -8,7 +26,7 @@
  *
  * Usage: echod
  *
  *
  * Usage: echod
  *
- * $Id: SimpleEchoTCPServer.c,v 1.3 2001/06/12 22:17:22 piccardi Exp $ 
+ * $Id: SimpleEchoTCPServer.c,v 1.4 2001/09/09 22:45:34 piccardi Exp $ 
  *
  ****************************************************************/
 /* 
  *
  ****************************************************************/
 /* 
index 5a7ba886a2d3411e5049c9b8d38f3efd8e99feef..a018f335a4851ade40190654a5010b76097a482e 100644 (file)
@@ -1,3 +1,32 @@
+/* SockRead.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/****************************************************************
+ *
+ * Routine SockRead
+ * Routine to read an exact number of bytes from a socket
+ *
+ * Author: Simone Piccardi
+ * Jun. 2001
+ *
+ * $Id: SockRead.c,v 1.3 2001/09/09 22:45:34 piccardi Exp $ 
+ *
+ ****************************************************************/
 #include <unistd.h>
 #include <errno.h>
 
 #include <unistd.h>
 #include <errno.h>
 
index 466807ce2370ab209be9db207548f11c4d7ff35f..c0a41d9abc7d2828db661bc4ff0a7fce7b330180 100644 (file)
@@ -1,3 +1,32 @@
+/* SockWrite.c
+ * 
+ * Copyright (C) 2001 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/****************************************************************
+ *
+ * Routine SockWrite
+ * Routine to write an exact number of bytes into a socket
+ *
+ * Author: Simone Piccardi
+ * Jun. 2001
+ *
+ * $Id: SockWrite.c,v 1.3 2001/09/09 22:45:34 piccardi Exp $ 
+ *
+ ****************************************************************/
 #include <unistd.h>
 #include <errno.h>
 
 #include <unistd.h>
 #include <errno.h>