Aggiunte i listati per poter usare le modifiche di Mirko, con la generazione
authorSimone Piccardi <piccardi@gnulinux.it>
Thu, 3 Apr 2003 22:33:29 +0000 (22:33 +0000)
committerSimone Piccardi <piccardi@gnulinux.it>
Thu, 3 Apr 2003 22:33:29 +0000 (22:33 +0000)
separata delle figure con gli esempi di codice. Qui ci va tutto quello che
prima era messo in un environment lstlisting

listati/ForkTest.c [new file with mode: 0644]
listati/char_list.c [new file with mode: 0644]
listati/env_ptr.c [new file with mode: 0644]
listati/exec_sample.c [new file with mode: 0644]
listati/main_def.c [new file with mode: 0644]
listati/option_code.c [new file with mode: 0644]
listati/pi.c [new file with mode: 0644]
listati/vect.c [new file with mode: 0644]

diff --git a/listati/ForkTest.c b/listati/ForkTest.c
new file mode 100644 (file)
index 0000000..3ca965f
--- /dev/null
@@ -0,0 +1,44 @@
+#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;
+}
diff --git a/listati/char_list.c b/listati/char_list.c
new file mode 100644 (file)
index 0000000..0044b02
--- /dev/null
@@ -0,0 +1 @@
+    char *arg0, char *arg1,  ..., char *argn, NULL
diff --git a/listati/env_ptr.c b/listati/env_ptr.c
new file mode 100644 (file)
index 0000000..80bd95b
--- /dev/null
@@ -0,0 +1 @@
+    extern char ** environ;
diff --git a/listati/exec_sample.c b/listati/exec_sample.c
new file mode 100644 (file)
index 0000000..e9f719c
--- /dev/null
@@ -0,0 +1 @@
+    int execl(const char *path, const char *arg, ...);
diff --git a/listati/main_def.c b/listati/main_def.c
new file mode 100644 (file)
index 0000000..f653bde
--- /dev/null
@@ -0,0 +1 @@
+    int main (int argc, char *argv[])
diff --git a/listati/option_code.c b/listati/option_code.c
new file mode 100644 (file)
index 0000000..7918bb7
--- /dev/null
@@ -0,0 +1,28 @@
+    opterr = 0;  /* don't want writing to stderr */
+    while ( (i = getopt(argc, argv, "hp:c:e:")) != -1) {
+        switch (i) {
+        /* 
+         * Handling options 
+         */ 
+        case 'h':   /* help option */
+            printf("Wrong -h option use\n");
+            usage();
+            return -1;
+            break;
+        case 'c':   /* take wait time for children */
+            wait_child = strtol(optarg, NULL, 10);    /* convert input */
+            break;
+        case 'p':   /* take wait time for children */
+            wait_parent = strtol(optarg, NULL, 10);   /* convert input */
+            break;
+        case 'e':   /* take wait before parent exit */
+            wait_end = strtol(optarg, NULL, 10);      /* convert input */
+            break;
+        case '?':   /* unrecognized options */
+            printf("Unrecognized options -%c\n",optopt);
+            usage();
+        default:    /* should not reached */
+            usage();
+        }
+    }
+    debug("Optind %d, argc %d\n",optind,argc);
diff --git a/listati/pi.c b/listati/pi.c
new file mode 100644 (file)
index 0000000..1ded269
--- /dev/null
@@ -0,0 +1 @@
+     double pi = 3.14;
diff --git a/listati/vect.c b/listati/vect.c
new file mode 100644 (file)
index 0000000..87641d6
--- /dev/null
@@ -0,0 +1 @@
+    int vect[100];