Bug 18734 - getpid() does not return pid if called from a thread
getpid() does not return pid if called from a thread
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i386 Linux
low Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
: FutureFeature
Depends On:
  Show dependency treegraph
Reported: 2000-10-09 14:34 EDT by rodrigc
Modified: 2016-11-24 10:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2000-10-09 14:34:06 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description rodrigc 2000-10-09 14:34:03 EDT
With glibc-2.1.92-5, getpid() does not return the pid of the process when
called from within a thread.  This problem exists in earlier versions of
glibc as well.
I've mentioned it here:
Here is a test-case:
#include "stdlib.h"
#include "pthread.h"
void print_message_function (void *ptr);
int main (int argc, char **argv)
  pthread_t thread1, thread2;
  char *message1 = "Thread 1";
  char *message2 = "Thread 2";
  int status;
  pthread_create (&thread1, NULL,
                  (void *) &print_message_function, (void *) message1);
  pthread_create (&thread2, NULL,
                  (void *) &print_message_function, (void *) message2);
  pthread_join(thread1, (void **)&status);
  pthread_join(thread2, (void **)&status);
  exit (0);
void print_message_function(void *ptr)
      int i;
      for(i=0; i < 20; i++)
          printf("%s:  pid: %d\n", ptr, getpid());
Comment 1 Jakub Jelinek 2000-10-11 04:19:39 EDT
That's how threads work in Linux since linuxthreads have been implemented.
This can change only if Linus accepts kernel patches which will actually
make sharing of pids between threads possible. Linus actually put a small
part of the needed changes into 2.4.0-testX (forgot what X it was) but then
backed it out.
Ben La Haise (bcrl@redhat.com) is working on new set of patches, if Linus
accepts them, then glibc will have much faster threads on those kernels and
they will share pid etc. But until he does, there is nothing glibc can do
about it.

Note You need to log in before you can comment on or make changes to this bug.