pid=fork()로 자식 생성후, sleep문이 먹질 않습니다.

berry91의 이미지

부모가 잠을 안자요...
저와같이 이틀째 밤새고있어요....
pid =fork()로 pid를 생성했는데,,,
자식에겐 잘 들어가는데 부모의 로직에 잘 안들어가요...
자식에게 몇번 들어가고 부모의 로직에 한꺼번에 3개씩 들어가기도하고...
그래서 시그널을 블록시켜줬더니... 이제 부모의 로직에 들어가긴하는데,

sleep문을 안먹어요...

리눅스에서 작업하고있습니다..
혹시 아래의 소스를 잠시보시고 왜 sleep 안먹는지 아시거나,,, 껀덕지가 있으시면 답변달아주세요 ㅠㅠ

// 부모
if( pid != 0 ) {

printf(" 첫수행이 아닐 때의 부모에 들어왔네요.\n");

activePcb->next->remainingcputime--;
dispatcherTimer++;

sigemptyset (&set); // 빈 시그널 집합 생성 // unblock SIGSTP if necessary (BSD/OS X)
sigaddset (&set, SIGALRM); // 시그널을 추가합니다.
sigaddset (&set, SIGCHLD); // 시그널을 추가합니다.
sigprocmask (SIG_BLOCK, &set, NULL); // 블록화될 시그널을 설정합니다
nSleep(1);
sigprocmask (SIG_UNBLOCK, &set, NULL); // 언블록화될 시그널을 설정합니다

act.sa_handler = signalHandler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGCONT, &act, NULL);

// 수행을 완료한 프로세스를 종료합니다.
if( activePcb->next->remainingcputime == 0 ) {

// 원래 수행하려 했던 프로세스 사살
if(kill(activePcb->next->pid, SIGINT)) {
fprintf(stderr, "terminate of %d failed", (int)activePcb->next->pid);
}

//waitpid(activePcb->next->pid, &status, 0);
pause();

// 수행하려 했던 프로세스를 수행하기 위해 만들었던 자식 죽이기
if(kill(pid, SIGINT)) {
fprintf(stderr, "terminate of %d failed", (int)activePcb->next->pid);
}

//wait(&status);
pause();
}

else {

// 원래 수행 하려 했던 프로세스 중단
if(kill(activePcb->next->pid, SIGTSTP)) {
fprintf(stderr, "stop of %d failed", (int)activePcb->next->pid);
}

//waitpid(activePcb->next->pid, &status, 0);
pause();

// 수행하려 했던 프로세스를 수행하기 위해 만들었던 자식 죽이기
if(kill(pid, SIGINT)) {
fprintf(stderr, "terminate of %d failed", (int)activePcb->next->pid);
}

//wait(&status);
pause();
}
}

// 자식
else {

printf(" 첫수행이 아닐 때의 자식에 들어왔네요.\n");
printf("제계할 프로세스 id : %7d\n", activePcb->next->pid);
kill(activePcb->next->pid, SIGCONT);
}
}

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.