Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Sébastien Roret" <sroret@eprocess.fr>
To: gdb@sources.redhat.com
Subject: fork and pthreads
Date: Fri, 30 Sep 2005 10:23:00 -0000	[thread overview]
Message-ID: <loom.20050930T114252-296@post.gmane.org> (raw)

Hi, 
 
I'm having some problems using fork() with threads. 
I'm using a debian linux on Intel, gdb 6.3, glibc 2.3.3 and 2.3.5 
If I call forks before using threads it's ok, but not the other way. 
The problem occurs only with gdb. 
See below the testcase and output I got. 
My question : is it a bug, or did I missed something ? 
 
Thanks for any ideas. 
 
 
 
#include <sys/types.h> 
#include <unistd.h> 
#include <pthread.h> 
 
void* start_routine(void *arg) 
{ 
        printf("start_routine\n"); 
} 
 
int main() 
{ 
  pid_t pid; 
  pthread_t thread; 
  int status; 
 
  printf("pid=%d\n", getpid()); 
 
  pthread_create(&thread, NULL, &start_routine, NULL); 
  pthread_join(thread, NULL); 
  perror("join"); 
 
  pid = fork(); 
 
  printf("fork pid = %d\n", pid); 
  if( pid == -1 ) 
  { 
         perror( "fork" ); 
         abort(); 
  } 
  else if( pid == 0 ) 
  { 
        printf("pid = %d\n", pid); 
        sleep(1); 
        return 0; 
  } 
  else 
  { 
       printf("waiting child pid = %d\n", pid); 
       printf("wait=%d\n", wait( &status )); 
       printf("status=%d\n", status ); 
       return 0; 
  } 
} 
 
Then : 
$ gcc pthread_fork.c -o pthread_fork -lpthread 
$ gdb ./pthread_fork 
GNU gdb 6.3-debian 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB.  Type "show warranty" for details. 
This GDB was configured as "i386-linux"...Using host libthread_db library 
"/lib/tls/libthread_db.so.1". 
 
(gdb) r 
Starting program: /tmp/pthread_fork 
[Thread debugging using libthread_db enabled] 
[New Thread 1075145376 (LWP 10278)] 
pid=10278 
[New Thread 1083534256 (LWP 10283)] 
start_routine 
[Thread 1083534256 (LWP 10283) exited] 
join: Success 
ptrace: No such process. 
thread_db_get_info: cannot get thread info: generic error 
(gdb) fork pid = 0 
pid = 0 
fork pid = 10284 
waiting child pid = 10284 
 
 
 
 
 


             reply	other threads:[~2005-09-30 10:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-30 10:23 Sébastien Roret [this message]
2005-09-30 13:08 ` Daniel Jacobowitz
2005-09-30 14:49 ` Sébastien Roret

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20050930T114252-296@post.gmane.org \
    --to=sroret@eprocess.fr \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox