프로세스 생성에 관한 질문입니다.
글쓴이: ar / 작성시간: 월, 2004/09/06 - 4:54오후
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <pthread.h>
#define TRUE 1
#define FALSE 0
int main()
{
int i, j;
pid_t p[3], p1, p2, p3;
int flag;
flag = 0; i = 1; j = 1;
while ( TRUE )
{
for ( i = 0; i < 3; i++ )
{
if ( (p[i] = vfork()) == 0 )
{
if ( i == 0 )
{
execl(" 어떤 플그램 ", " ", NULL);
}
else if ( i == 1 )
{
while ( TRUE )
{
if ( (i++ % 7) == 0 )
{
kill(p[0], SIGINT);
flag = 1;
break;
}
fprintf(stdout, "%d u \n", i);
sleep(1);
}
}
else
{
while ( TRUE )
{
if ( (j++ % 11) == 0 )
{
kill(p[0], SIGINT);
kill(p[1], SIGINT);
break;
}
fprintf(stdout, "%d t \n", j);
sleep(1);
}
}
}
}
fprintf(stdout, "debug - hello world 1\n");
waitpid(p[0], 0, 0);
fprintf(stdout, "debug - hello world 2\n");
waitpid(p[1], 0, 0);
fprintf(stdout, "debug - hello world 3\n");
if ( flag )
{
kill(p[2], SIGINT);
flag = 0;
}
waitpid(p[2], 0, 0);
fprintf(stdout, "debug - hello world 4\n");
}
return 0;
}
코드가 대충 이런데요.. 세번째 프로세스의 실행이 안되네요..
Forums:


댓글 달기