자식 프로세스의 관리 및 종료 ... fork() / execl() 인데 .. 오류가 있네요 ...

Sailor_moon의 이미지

안녕하세요, 지금 , fork (), execl() 을 이용한 멀티프로세싱 공부중인데 , 잘 안되어서
질문 올립니다.

pid_t* pid_array = malloc(sizeof(pid_t)*atoi(argv[1]))
.... 생략 ...
  while (i<atoi(argv[1]))
    {
	pid_t j;
	int test_exec;
	printf("I am forking now...\n");
	j = fork();
	printf("%d\n",j);
	if (j==0){				
		// Child process case 
		//test_exec= execl("/bin/echo","/bin/echo" ,"hi",NULL);
		printf("callString: %s\n",callString);
		test_exec = execl("./amazing_client","./amazing_client", c_id,argv[1],argv[2],argv[3],c_mazePort,logFileName,NULL);
		if(test_exec <0){
			printf("%s\n", strerror(errno));
		}	
		printf("return value of %d",test_exec);
		//execl("./amazing_client", callString);
	}
	else if (j<0){
		printf("Failed the call fork()\n");
		exit(1);
	}
	else {
		pid_array[i] = j;
		waitpid(pid_array[i], (int*)0, WNOHANG);
		printf("I am a parents .. %d forked \n", i+1);
	}
	i++;
    } // end of while ... 
 
    --i;
	int count;					// tracking child procedures ...
	int stop_count;
	while(1){			
		stop_count =0;
		for(count =0; count <i; ++count){
			if(waitpid(pid_array[count], (int*)0, WNOHANG)) ++stop_count;	//Parents process will wait until every children has been done thier work
			if (i == stop_count){
				printf("%d children all stopped\n", count);
				break;
			}
		}
	}
	free(pid_array);

일단은 위와같은 소스구요, 인자값으로 받은 횟수 만큼 ,
부모 프로세스가 , 자식 프로세서로 다른 c 프로그램인 amazing_client 를 실행 시키는 것 입니다.
인자로 3을 받았다면 , 3개의 자식 프로세스가 , 클라이언트를 실행하면서 callString 인자를 가지고
amazing_client 를 실행 되게 하는 것인데, 마지막 자삭의 종료가 제대로 이루어 지질 않네요 .

고수분들 도와 주세요 ~