hugh@sophia.COM (Hugh Bussell) (06/21/91)
This is posted for Hugh Bussel. Do not send anything to me. Send all comments/chat/flames/etc to hugh@sophia.com. ____ I've run into some strange behavior running Coherent 3.1.0. Since I'm so new at *nix system programming I'm not certain where the fault lies. (Read that, I think it's a bug, but I'm not going to say so in case I've made some obvious mistake!) The following program does little except to fork off children and wait for them to exit. If you gave a command line argument, the program tests if the pid number of the child exceeds the argument, exits if it does and forks another child if not. If you didn't give an argument, the program will keep forking and waiting and forking and waiting.... Running the program with no arguments works fine. As long as the current process number is less than 7167 and the argument is less than 7167 things work fine. If either the current process number or the command line argument are greater than 7167, process dumps core saying "bad system call". And for real excitement, running the program with an argument of 7167 causes a system panic! The wait() call somehow seems to be involved with the problem. Without it, I don't get the bad system call. Of course, without it, the forks soon fail because of the zombie processes left by the parent. If this is a bug, I'll report it. If anybody sees some subtle problem with my code, send me the explanation and I'll summarize. And if I've missed something obvious, go ahead and flame. I'll still learn a lot. (Besides, I've got a six month old son. Deprive a man of enough sleep and he won't notice the insults.) Hugh Bussell hugh@sophia.com Sophia Systems and Technology 777 California Ave Palo Alto, CA 94304 (415) 493-6700 =========== Here's the program =============================== #include <stdio.h> main(argc,argv) int argc; char *argv[]; { int test = 1 ; int tine=1; int mypid; int testval; if ( argc < 2 ) test = 0; else { testval = atoi(argv[1]); } while ( tine ) { if (( tine = fork()) < 0) { printf("fork failed!\n"); exit(1); } mypid = getpid(); if( tine != 0 ) { printf("My pid = %d\n",mypid); wait(); if (test) { if (testval <= tine) exit(2); } } } /* end while */ printf("Process %d exiting now.\n",mypid); exit(0); } /* end main */ Do NOT write to the below address! -- -------- | ---- | ZAP!! | / | A.K.A. Paul Eastham | /_ | zap@netcom.com | / | Los Altos, CA --------