ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • GDB로 multiprocess 디버깅할때
    개발하면서/etc 2012. 10. 28. 22:21
    반응형

    Redis의 aof에서  fork하는 부분이 있습니다.

    if (server.aof_child_pid != -1) return REDIS_ERR;
        start = ustime();
        if ((childpid = fork()) == 0) {
            char tmpfile[256];
    
            /* Child */
            if (server.ipfd > 0) close(server.ipfd);
            if (server.sofd > 0) close(server.sofd);
            snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
            if (rewriteAppendOnlyFile(tmpfile) == REDIS_OK) {
                exitFromChild(0);
            } else {
                exitFromChild(1);
            }
        } else {
            /* Parent */
            server.stat_fork_time = ustime()-start;
            if (childpid == -1) {
                redisLog(REDIS_WARNING,
                    "Can't rewrite append only file in background: fork: %s",
                    strerror(errno));
                return REDIS_ERR;
            }
            redisLog(REDIS_NOTICE,
                "Background append only file rewriting started by pid %d",childpid);
            server.aof_rewrite_scheduled = 0;
            server.aof_rewrite_time_start = time(NULL);
            server.aof_child_pid = childpid;
            updateDictResizePolicy();
            /* We set appendseldb to -1 in order to force the next call to the
    * feedAppendOnlyFile() to issue a SELECT command, so the differences
    * accumulated by the parent into server.aof_rewrite_buf will start
    * with a SELECT statement and it will be safe to merge. */
            server.aof_selected_db = -1;
            return REDIS_OK;
        }
    

    구글한테 물어보니 다음과 같은 모드가 있었네요.

    set follow-fork-mode mode

    Set the debugger response to a program call of fork or vfork.
    A call to fork or vfork creates a new process. The mode argument can be:

    parent

            The original process is debugged after a fork. The child process runs unimpeded. This is the default.

    child

            The new process is debugged after a fork. The parent process runs unimpeded.

     

    show follow-fork-mode

            Display the current debugger response to a fork or vfork call.

     

    동시에 두개를 볼 수 는 없나봅니다.(child / parent) 생각해보니 두개 동시에 보면 디버깅 하는 입장에서 더 괴롭겠어요 ㅋㅋ

    혹시 동시에 두개 하는 방법이 있나요?

     

    부지런히 코드 타이핑해서 생각한걸 코드로 뚝딱뚝딱 만들 수 있는 날이 왔으면 좋겠습니다 : )

     

     

    GDB모드 원문 url : http://sunsite.ualberta.ca/Documentation/Gnu/gdb-5.0/html_node/gdb_25.html

    반응형

    댓글

Designed by Tistory.