debugging child threads

Discussion in 'C Programming' started by sunil, Aug 2, 2006.

  1. sunil

    sunil Guest

    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
     
    sunil, Aug 2, 2006
    #1
    1. Advertising

  2. sunil <> wrote:

    > 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.programmer or comp.programming.threads.)

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

    http://www.ungerhu.com/jxh/clc.welcome.txt
    http://c-faq.com
    http://benpfaff.org/writings/clc/off-topic.html

    for posting guidelines and frequently asked questions. Thank you.

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
     
    Christopher Benson-Manica, Aug 2, 2006
    #2
    1. Advertising

  3. sunil

    Richard Guest

    "sunil" <> writes:

    > 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:

    http://sources.redhat.com/gdb/current/onlinedocs/gdb_6.html#SEC45

    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.
     
    Richard, Aug 3, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bhchng
    Replies:
    0
    Views:
    669
    bhchng
    Jan 13, 2004
  2. davout
    Replies:
    0
    Views:
    562
    davout
    Apr 18, 2004
  3. leon
    Replies:
    0
    Views:
    439
  4. Bryan Ax
    Replies:
    6
    Views:
    555
    Peter Flynn
    May 17, 2006
  5. Jeff Rodriguez
    Replies:
    23
    Views:
    1,160
    David Schwartz
    Dec 9, 2003
Loading...

Share This Page