Cover V05, I10
Article
Listing 1
Listing 10
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6
Listing 7
Listing 8
Listing 9

oct96.tar


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);
}