자식 프로세스의 관리 및 종료 ... 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 를 실행 되게 하는 것인데, 마지막 자삭의 종료가 제대로 이루어 지질 않네요 .

고수분들 도와 주세요 ~

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.