X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FForkTest.c;h=03ddf75eadfe4c37ab7536cbe7d4e0401a0fcc1b;hp=6f733876f528246abb75a03fd12198deccf48f31;hb=da8455a295d5e2e237711cd930b7052f1b30ea38;hpb=351af2e8af7ee3a44410e3837934b45edfe10fc8 diff --git a/sources/ForkTest.c b/sources/ForkTest.c index 6f73387..03ddf75 100644 --- a/sources/ForkTest.c +++ b/sources/ForkTest.c @@ -26,7 +26,7 @@ * * Usage: forktest -h give all info's * - * $Id: ForkTest.c,v 1.3 2001/09/11 21:01:09 piccardi Exp $ + * $Id: ForkTest.c,v 1.6 2001/09/21 17:10:51 piccardi Exp $ * ****************************************************************/ /* @@ -46,23 +46,34 @@ int main(int argc, char *argv[]) /* * Variables definition */ - int i; - int nchild; + int nchild, i; pid_t pid; + 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 */ - while ( (i = getopt(argc, argv, "h")) != -1) { + while ( (i = getopt(argc, argv, "hp:c:e:")) != -1) { switch (i) { /* * Handling options */ - case 'h': + case 'h': /* help option */ printf("Wrong -h option use\n"); usage(); - return(0); + return -1; + break; + case 'c': /* take wait time for childen */ + wait_child = strtol(optarg, NULL, 10); /* convert input */ + break; + case 'p': /* take wait time for childen */ + 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); @@ -83,22 +94,27 @@ int main(int argc, char *argv[]) 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