All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jonathan A. George" <JAGeorge@greshamstorage.com>
To: linux-kernel@vger.kernel.org
Subject: Help? 2.4 to 2.6 pthread problem with popen in gdb
Date: Mon, 10 May 2004 17:37:32 -0500	[thread overview]
Message-ID: <40A0042C.6000603@greshamstorage.com> (raw)

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 );
};

                 reply	other threads:[~2004-05-10 22:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=40A0042C.6000603@greshamstorage.com \
    --to=jageorge@greshamstorage.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.