public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Help? 2.4 to 2.6 pthread problem with popen in gdb
@ 2004-05-10 22:37 Jonathan A. George
  0 siblings, 0 replies; only message in thread
From: Jonathan A. George @ 2004-05-10 22:37 UTC (permalink / raw)
  To: linux-kernel

Is there a work around for the wait4 failure in gdb when debugging a 
program that uses popen from within a pthread?

The behavior is:
correct 2.4
correct 2.4 in gdb 6.x
correct 2.6
failure 2.6 gdb 6.x

Even the most trivial program which uses popen from within a pthread 
will fail immediately, but ONLY under 2.6 and ONLY gdb.   This problem 
has manifested from 2.6.0 - 2.6.6 in the vanilla mainline kernels using 
the current libc/pthread/gdb/gcc from Debian Sid tested with each tool 
or kernel update.

--Jonathan--

P.S. Example code below compiles with g++ filename.cpp -lpthread

#include <iostream>
using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
void *
thread_start( void *thread_arg )
{
    cout << "arg=" << (long) thread_arg << endl;
    FILE *popen_file = popen( "ping -c3 127.0.0.1", "r" );
    cout << "errno=" << errno << endl;
    if( popen_file )
    {
        char linebuf[ 0xff ];
        char *fgets_result = NULL;
        while( NULL != (fgets_result =
            fgets( linebuf, sizeof( linebuf ), popen_file )) )
        {
            cout << "fgets_result=" << fgets_result;//<< endl;
        }
        int pclose_result = pclose( popen_file );
        cout << "pclose_result=" << pclose_result << endl;
    }
    return( NULL );
}

int
main()
{
    cout <<  "hello world" << endl;
    pthread_t tid = 0;
    pthread_attr_t pattr;
    pthread_attr_init( &pattr );
    pthread_attr_setdetachstate(
         &pattr, PTHREAD_CREATE_DETACHED );
    pthread_create(
         &tid, &pattr, thread_start, (void *) 12345L );
    //pthread_join( tid, NULL );
    cout << "sleeping" << endl;
    sleep( 20 );
    return( 0 );
};

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-05-10 22:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-10 22:37 Help? 2.4 to 2.6 pthread problem with popen in gdb Jonathan A. George

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox