debug a multi process in gdb?

debug a multi process in gdb?

Post by zhou jianxi » Tue, 01 May 2001 17:08:23

Hi all:

    if((pid = fork()<0)
        printf("fork error!.\n");
A:     printf("pid=%d.\n",pid);

when I debug it in gdb,set breakpoint at A,then run;after it print the value
of pid,the pid is larger 0(assume it is 1001),so it is the child process's
I have thought the pid should be 0 after I do :
gdb>attach 1001
but the pid was not changed.
what is wrong.
can anybody give help for me?
thx !



1. Problems with debugging multi-threaded application with gdb


I have problems with debugging multi-threaded application wtih dbg. The
below program runs perfectly without gdb. Under gdb (no breakpoints set) the
program terminates in either of the two assert() statements. I'm desperately
looking for the answer why.


#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <assert.h>

void *
thread_routine(void *a)
  unsigned int ret;


  ret = sleep(5);
  assert(ret == 0);            /* !!!!!!!!!!!!!!!!!!!! HERE (ret is equal 5)
!!!!!!!!!!!!!!!!!!!!!!! */


  return NULL;

  pthread_t pid;
  int i;
  int ret;

  /* we start with default attributes ... */
  for (i = 0; i < 10; i++)
    pthread_create(&pid, NULL, thread_routine, NULL);

  ret = sleep(10);
  assert(ret == 0);        /* !!!!!!!!!!!!!!!!!!!! HERE (ret is equal 10)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */

  return 0;

2. Unix - Frequently Asked Questions (Contents) [Frequent posting]

3. How can UNIX Multi-process with Multi-process interface

4. syslogd on NT

5. debugging a "buried" process with gdb

6. AMD K6-300 or IBM 333 ?

7. gdb question:debug child processes?

8. setting/ exporting environment variable in a script file

9. Help debugging child process w/gdb

10. debugging a child process fork() with GDB

11. Does anyone know how to debug multi-process programs using dbx?

12. ? multi home + multi cgi, multi email, multi log, multi support

13. Design of a server: multi-threaded or multi-processes?