#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <time.h>


int main()
{
     
     FILE *fp = fopen("test.txt", "wt");  //저장할 파일 생성.
     
     int i;     
     int j;      
     int k;       
     int status;
     time_t rawtime;                     // 시간 출력
     struct tm *timeinfo;

     int dead_child_pid;
     time(&rawtime);
     timeinfo = localtime(&rawtime);                

     pid_t pid;                         
     pid_t pid_child;                    //   부모와 자식의 pid확인 및 pid리턴값
     pid_t pid_parent;                   
      pid_t a[10];                           

   
   
    for(i=0; i<5;i++)
    {   
        pid = fork();
       
       
   
    if (pid == -1)
    {
        fprintf(stderr, "fork failed");
        return 1;
    }
    else if(pid==0)
    {
   
        for(j=0;j<5;j++)
        {
            printf("[%dprocess] #%d\n",getpid(),j);
        }
        return 0;
    }
    else
    {
        /*    while((dead_child_pid = waitpid(-1, &status, WNOHANG)) >0)
            {
                printf("%d [child] 종료. %d [부모]\n", dead_child_pid, getpid());
            }       1번
         */   
         /*   while(wait(NULL)!=-1 )
            {
                printf("%d [child] 종료. %d [부모]\n",wait(NULL),getpid());
            } 2번
            */
                

    }

    }

    return 0;
}


1번으로 while 문하면 전체 실행시간중에 자식이 하나 혹은 둘 정도 죽엇다고 뜸 안뜰때도 잇음
2번으로 하면 자식이 하나 종료되기전까지 다음께 블락되는거같은데..

참 병신같다 내가 참..