debugging child threads

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sunil

    debugging child threads

    Hi All,
    I am tring to debug the following program.I written this
    program in HP-Unix and I am using the GDB as a debugger.

    #include <stdio.h>
    #include<unistd .h>
    int main()
    {
    int pid;
    pid = fork();
    if(pid == 0)
    {
    printf("I am the child process,my processid is\t
    %d\n",getpid()) ;
    printf("I am the child's parent process,my processid
    is\t %d\n",getppid() );
    sleep(20);
    printf("I am the child process,my processid is\t
    %d\n",getpid()) ;
    printf("I am the child's parent process,my processid
    is\t %d\n",getppid() );
    }
    else
    {
    printf("I am the parent process,my processid is\t
    %d\n",getpid()) ;
    printf("I am the parent's parent process,my processid
    is\t %d\n",getppid() );
    }
    }

    While debugging using any debugger by default it will take only
    parent process to debug.If u want to debug the child process we have to
    use the "info threads" command and get the thread numbers.
    And we have to switch to the child thread,this is what the
    general procedure is.
    But in my case it is showing only one entry after executing the
    info threads command,I executed this command after the if loop.
    Could anybody suggest how to trap that child thread and how to
    debug that process.i put the break point at the if loop.If anybody
    couldn't get it plz revert back to me.

    Regards
    Sunil

  • Christopher Benson-Manica

    #2
    Re: debugging child threads

    sunil <sunil.vvn@gmai l.comwrote:
    I am tring to debug the following program.I written this
    program in HP-Unix and I am using the GDB as a debugger.
    (snip question relating to threads)

    (This question is better suited for a different newsgroup, possibly
    comp.unix.progr ammer or comp.programmin g.threads.)

    Your post is off-topic for comp.lang.c. Please visit





    for posting guidelines and frequently asked questions. Thank you.

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gma il.com | don't, I need to know. Flames welcome.

    Comment

    • Richard

      #3
      Re: debugging child threads

      "sunil" <sunil.vvn@gmai l.comwrites:
      Hi All,
      I am tring to debug the following program.I written this
      program in HP-Unix and I am using the GDB as a debugger.
      Hi sunil,

      You've already been informed that this is Off Topic here : but I just
      happened to be reading something recently which might help you.

      It can be confusing. But gdb stops all execution of all
      threads at a break. See here for further info:



      I'm assuming you DID set a breakpoint at if(pid==0) ?

      good luck,

      r.
      >
      #include <stdio.h>
      #include<unistd .h>
      int main()
      {
      int pid;
      pid = fork();
      if(pid == 0)
      {
      printf("I am the child process,my processid is\t
      %d\n",getpid()) ;
      printf("I am the child's parent process,my processid
      is\t %d\n",getppid() );
      sleep(20);
      printf("I am the child process,my processid is\t
      %d\n",getpid()) ;
      printf("I am the child's parent process,my processid
      is\t %d\n",getppid() );
      }
      else
      {
      printf("I am the parent process,my processid is\t
      %d\n",getpid()) ;
      printf("I am the parent's parent process,my processid
      is\t %d\n",getppid() );
      }
      }
      >
      While debugging using any debugger by default it will take only
      parent process to debug.If u want to debug the child process we have to
      use the "info threads" command and get the thread numbers.
      And we have to switch to the child thread,this is what the
      general procedure is.
      But in my case it is showing only one entry after executing the
      info threads command,I executed this command after the if loop.
      Could anybody suggest how to trap that child thread and how to
      debug that process.i put the break point at the if loop.If anybody
      couldn't get it plz revert back to me.
      >
      Regards
      Sunil
      >
      --
      Lint early. Lint often.

      Comment

      Working...