[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [issues] getpid: to cache or not to cache



Renzo Davoli wrote:

...

The problem is that in some point of time the implementation of the glibc call added a cache to store the value of a previous getpid for
all later calls.
Unfortunately this change broke some programs (e.g. cryopid is not
working properly), we are having similar problems.

By the way, the manpage for clone(2) suggests a suitable workaround for programs that necessarily need the uncached pid value:

<cut>
BUGS
       Versions of the GNU C library that include the NPTL thread\u2010
       ing library contain a wrapper function  for  getpid()  that
       performs  caching of PIDs.  In programs linked against such
       libraries, calls to getpid() may  return  the  same  value,
       even  when  the threads were not created using CLONE_THREAD
       (and thus are not in the same thread group).   To  get  the
       truth,  it may be necessary to use code such as the follow\u2010
       ing

           #include <syscall.h>

           pid_t mypid;

           mypid = syscall(SYS_getpid);
</cut>

--
Maxim