Bug 18734 - getpid() does not return pid if called from a thread
Summary: getpid() does not return pid if called from a thread
Status: CLOSED DEFERRED
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc   
(Show other bugs)
Version: 7.0
Hardware: i386
OS: Linux
low
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Aaron Brown
URL:
Whiteboard:
Keywords: FutureFeature
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-10-09 18:34 UTC by rodrigc
Modified: 2016-11-24 15:07 UTC (History)
1 user (show)

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


Attachments (Terms of Use)

Description rodrigc 2000-10-09 18:34:03 UTC
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:
http://sources.redhat.com/ml/libc-alpha/2000-10/msg00081.html
 
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 08:19:39 UTC
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.