X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2FForkTest.c;fp=sources%2FForkTest.c;h=da38629b41892b6be703821222303d4da4073576;hb=0d1802dcd969187e6133ba143ebc473c9fefc259;hp=0000000000000000000000000000000000000000;hpb=67a484c6ccfdb14cdd37678ca5df0db699801935;p=gapil.git diff --git a/sources/ForkTest.c b/sources/ForkTest.c new file mode 100644 index 0000000..da38629 --- /dev/null +++ b/sources/ForkTest.c @@ -0,0 +1,95 @@ +/**************************************************************** + * + * Program ForkTest.c: + * Program to test process creation + * + * Author: Simone Piccardi + * Sep. 2001 + * + * Usage: forktest -h give all info's + * + * $Id: ForkTest.c,v 1.1 2001/09/09 17:39:15 piccardi Exp $ + * + ****************************************************************/ +/* + * Include needed headers + */ +#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; + /* + * Input section: decode command line parameters + * Use getopt function + */ + opterr = 0; /* don't want writing to stderr */ + while ( (i = getopt(argc, argv, "h")) != -1) { + switch (i) { + /* + * Handling options + */ + case 'h': + printf("Wrong -h option use\n"); + usage(); + return(0); + break; + case '?': /* unrecognized options */ + printf("Unrecognized options -%c\n",optopt); + usage(); + default: /* should not reached */ + usage(); + } + } + /* *********************************************************** + * + * Options processing completed + * + * Main code beginning + * + * ***********************************************************/ + /* 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