+/* ForkTest.c
+ *
+ * Copyright (C) 2001 Simone Piccardi
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
/****************************************************************
*
* Program ForkTest.c:
*
* Usage: forktest -h give all info's
*
- * $Id: ForkTest.c,v 1.1 2001/09/09 17:39:15 piccardi Exp $
+ * $Id: ForkTest.c,v 1.2 2001/09/09 22:45:34 piccardi Exp $
*
****************************************************************/
/*
/* loop to fork children */
for (i=0; i<nchild; i++) {
if ( (pid = fork()) < 0) {
- printf("Error on %d child creation, %s\n", i, strerror(errno));
+ printf("Error on %d child creation, %s\n", i+1, strerror(errno));
}
if (pid == 0) { /* child */
- printf("Child %d successfully executing\n", i++);
+ printf("Child %d successfully executing\n", ++i);
sleep(2);
printf("Child %d exiting\n", i);
exit(0);
} else { /* parent */
- printf("Spawned %d child, pid %d \n", i, pid);
+ printf("Spawned %d child, pid %d \n", i+1, pid);
}
}
/* normal exit */