Listing 8: fork.c
/*
* fork.c - simple fork test
*/
#include
#define FORK_MAX=256;
main(argc, argv)
int argc;
char *argv[];
{
int i, cpid, fork_max=FORK_MAX;
if ( argc == 2 ) fork_max=atoi(argv[1]);
for (i=0; i < fork_max; i++)
switch ( cpid=fork() ) {
case -1:
printf("# fork exit: %d\n", i);
exit(1);;
case 0: /* child returns here */
exit(0);
default: /* parent receives process id of child */
;
}
printf("# fork ok: %d\n", fork_max);
exit(0);
}
|