A parte che il tuo codice genera un po di errori, solitamente è sempre meglio chiamare una exit(0) all'interno della condizione in cui crei il processo.
Vedi un po se questo codice ti schiarisce le idee;
Output:codice:#include <stdio.h> #include <stdlib.h> #include <unistd.h> #define NPR 3 int main(void) { int i; pid_t pid[3]; /*array di processi*/ printf("I am the parent process with PID %d\n", getpid()); for(i=0;i<NPR;i++) { if((pid[i]=fork())==0) { printf("I am the son process with PID %d and my parent is %d\n", getpid(), getppid()); exit(0); } } return 0; }
~/Desktop$ gcc p.c -o p
~/Desktop$ ./p
I am the parent process with PID 7000
I am the son process with PID 7001 and my parent is 7000
I am the son process with PID 7002 and my parent is 7000
I am the son process with PID 7003 and my parent is 7000
~/Desktop$![]()

Rispondi quotando