#include #include #define NULL 0 int main(){ char * str[3]= {"a", "b", "c"}; char * pass_arg[4]; int i; /* MUST allocate space for the arguments!!! */ for (i = 0; i < 3; i++) { pass_arg[i] = (char *) malloc(sizeof(str[i]) + 1); strcpy(pass_arg[i], str[i]); } /* The LAST argument MUST be NULL */ pass_arg[3] = NULL; if (fork() == 0){ /* this is child */ execv("child2",pass_arg); exit(1); /* should never get here; terminate */ } /* Parent code here */ printf("Process[%d]: Parent in execution ... \n", getpid() ); sleep(2); if (wait(NULL) > 0) /* Child terminating */ printf("Process[%d]: Parent detects terminating child \n", getpid() ); printf("Process[%d]: Parent terminating....\n", getpid() ); }