From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23049 invoked by alias); 30 Sep 2005 10:23:10 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 23033 invoked by uid 22791); 30 Sep 2005 10:23:03 -0000 Received: from main.gmane.org (HELO ciao.gmane.org) (80.91.229.2) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Fri, 30 Sep 2005 10:23:02 +0000 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1ELI0p-00072g-2i for gdb@sources.redhat.com; Fri, 30 Sep 2005 12:21:07 +0200 Received: from 80.124.159.225 ([80.124.159.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 Sep 2005 12:21:06 +0200 Received: from sroret by 80.124.159.225 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 30 Sep 2005 12:21:06 +0200 To: gdb@sources.redhat.com From: =?utf-8?b?U8OpYmFzdGllbg==?= Roret Subject: fork and pthreads Date: Fri, 30 Sep 2005 10:23:00 -0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-SW-Source: 2005-09/txt/msg00247.txt.bz2 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 #include #include 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