projects
/
gapil.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Aggiornamento al 2010 delle note di copyright
[gapil.git]
/
sources
/
ForkTest.c
diff --git
a/sources/ForkTest.c
b/sources/ForkTest.c
index d57ef7a7436c469f0620ce45c3dfee50d9d31fe1..1965ec8f4fd232420869bff4297d95fd3fcbbdac 100644
(file)
--- a/
sources/ForkTest.c
+++ b/
sources/ForkTest.c
@@
-26,8
+26,6
@@
*
* Usage: forktest -h give all info's
*
*
* Usage: forktest -h give all info's
*
- * $Id: ForkTest.c,v 1.4 2001/09/14 22:16:41 piccardi Exp $
- *
****************************************************************/
/*
* Include needed headers
****************************************************************/
/*
* Include needed headers
@@
-36,7
+34,10
@@
#include <stdlib.h> /* C standard library */
#include <unistd.h> /* unix standard library */
#include <stdio.h> /* standard I/O library */
#include <stdlib.h> /* C standard library */
#include <unistd.h> /* unix standard library */
#include <stdio.h> /* standard I/O library */
-#include <string.h> /* string functions */
+#include <string.h> /* C strings library */
+
+#include "Gapil.h"
+#include "macros.h"
/* Help printing routine */
void usage(void);
/* Help printing routine */
void usage(void);
@@
-48,14
+49,15
@@
int main(int argc, char *argv[])
*/
int nchild, i;
pid_t pid;
*/
int nchild, i;
pid_t pid;
- int wait_child=0;
- int wait_parent=0;
+ int wait_child = 0;
+ int wait_parent = 0;
+ int wait_end = 0;
/*
* Input section: decode command line parameters
* Use getopt function
*/
opterr = 0; /* don't want writing to stderr */
/*
* Input section: decode command line parameters
* Use getopt function
*/
opterr = 0; /* don't want writing to stderr */
- while ( (i = getopt(argc, argv, "h
p:c
:")) != -1) {
+ while ( (i = getopt(argc, argv, "h
sp:c:e
:")) != -1) {
switch (i) {
/*
* Handling options
switch (i) {
/*
* Handling options
@@
-66,10
+68,16
@@
int main(int argc, char *argv[])
return -1;
break;
case 'c': /* take wait time for childen */
return -1;
break;
case 'c': /* take wait time for childen */
- wait_child
=
strtol(optarg, NULL, 10); /* convert input */
+ wait_child
=
strtol(optarg, NULL, 10); /* convert input */
break;
case 'p': /* take wait time for childen */
break;
case 'p': /* take wait time for childen */
- wait_parent=strtol(optarg, NULL, 10); /* convert input */
+ 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 's':
+ Signal(SIGCHLD, HandSigCHLD);
break;
case '?': /* unrecognized options */
printf("Unrecognized options -%c\n",optopt);
break;
case '?': /* unrecognized options */
printf("Unrecognized options -%c\n",optopt);
@@
-90,7
+98,7
@@
int main(int argc, char *argv[])
usage();
}
nchild = atoi(argv[optind]);
usage();
}
nchild = atoi(argv[optind]);
- printf("
Test for forking %d child\n"
, nchild);
+ printf("
Process %d: forking %d child\n", getpid()
, nchild);
/* 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) {
@@
-101,7
+109,7
@@
int main(int argc, char *argv[])
if (pid == 0) { /* child */
printf("Child %d successfully executing\n", ++i);
if (wait_child) sleep(wait_child);
if (pid == 0) { /* child */
printf("Child %d successfully executing\n", ++i);
if (wait_child) sleep(wait_child);
- printf("Child %d
exiting\n", i
);
+ printf("Child %d
, parent %d, exiting\n", i, getppid()
);
exit(0);
} else { /* parent */
printf("Spawned %d child, pid %d \n", i+1, pid);
exit(0);
} else { /* parent */
printf("Spawned %d child, pid %d \n", i+1, pid);
@@
-110,6
+118,7
@@
int main(int argc, char *argv[])
}
}
/* normal exit */
}
}
/* normal exit */
+ if (wait_end) sleep(wait_end);
return 0;
}
/*
return 0;
}
/*
@@
-118,7
+127,12
@@
int main(int argc, char *argv[])
void usage(void) {
printf("Program forktest: fork a given number of child \n");
printf("Usage:\n");
void usage(void) {
printf("Program forktest: fork a given number of child \n");
printf("Usage:\n");
- printf(" forktest [-h] child to fork \n");
+ printf(" forktest [-h]
[-p sec] [-c sec] [-e sec]
child to fork \n");
printf(" -h print this help\n");
printf(" -h print this help\n");
+ printf(" -s install signal handler\n");
+ printf(" -p sec wait sec seconds before next fork\n");
+ printf(" -c sec wait sec seconds before child termination\n");
+ printf(" -e sec wait sec seconds before parent return\n");
+
exit(1);
}
exit(1);
}