sigwait 함수 관련

asleea의 이미지

책 예제에서 SIGUSR1을 블록시켜 놓은 상태에서 sigwait()을 이용해서 SIGUSR1을 기다리는 부분이 있습니다.

처음 생각에는 블록을 시켜 놓은 시그널을 기다린다는게 이상했는데 동작을 하더군요;;

그리고 몇 가지 동작을 실험해 보려고 SIGUSR1 핸들러를 작성해서 다시 동작 시켜보았습니다.

그런데 핸들러가 동작을 하지 않더군요.

그래서 이번에는 SIGUSR1블록을 풀어 놓은 상태에서 sigwait을 이용하여 SIGUSR1을 기다려보아도 핸들러가 동작을 하지 않습니다.;;

man page를 봐도 핸들러 관련 내용은 없는 것 같고

remove signal from the pending list of signals 라는 부분이 있는데 시그널 catch전 팬딩 상태에서 처리를 해버린다는 뜻 인가로 그래서 핸들러가 동작을 하지 않는 것이고 .?;;;;

아니면 제가 먼가 착각을 하고 있는지^^;;

아래는 테스트하려고 간단하게 작성한 코드입니다.
핸들러는 그냥 signal handler라는 구문을 프린트 해주는데 동작을 하지 않습니다 .ㅜㅜ

void handler(int signum)
{
        char buffer[] = "siganl hander\n";
        write(STDOUT_FILENO, buffer, sizeof(buffer));
}
 
 
int main()
{
        sigset_t set;
        int signum;
        sigemptyset(&set);
        sigaddset(&set, SIGUSR1);
//      sigprocmask(SIG_SETMASK, &set, NULL);
 
        struct sigaction act;
        act.sa_handler = handler;
        act.sa_flags = 0;
        sigaction(SIGUSR1 ,&act, NULL);
 
        fprintf(stderr, "%ld, %d\n", (long)getpid(), SIGUSR1);
        fprintf(stderr, "waiting for signal\n");
        sigwait(&set, &signum); 
        fprintf(stderr, "signal arrive\n");
        return 0;
}

익명 사용자의 이미지

The sigwait() function suspends execution of the calling thread until the delivery of one of the signals specified in the signal set set. The function accepts the signal (removes it from the pending list of signals), and returns the signal number in sig.

sigwait() 가 시그널을 기다리다 시그널이 도착하면 시그널 패딩 목록에서 기다리는 해당 시그널을 제거하고 반환된다고 하네요. 결과론적이지만 sigwait()가 패딩 목록에서 해당 시그널을 제거해서 핸들러 호출을 하지 못하는 것 같습니다. 하지만 sigwait() 이후에 들어오는 시그널은 핸들러로 처리합니다.

freemckang의 이미지

올리신 source code는 무엇을 의도하는 것인지요?

sigaction()으로 signal handler를 등록한 상황에서 sigwait()를 다시 한 이유는 무엇인지...?

잘 알고 계시겠지만, sigaction으로는 별도의 handler를 지정이 가능합니다만 sigwait는 해당 signal이 오면 바로 return을 칩니다. SIGUSR1이 올 때가지 기다리게 하려고 이렇게 구성하신 것이라면 구성이 잘못되었다고 보여지네요..

句日新, 日新 日新 又日新.

댓글 달기

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