Linus Torvalds wrote: > > On Sat, 5 Jun 2004, Davide Libenzi wrote: > >> It is likely used by pthread_self(), that is pretty much >> performance sensitive. I'd agree with Ulrich here. > > > It _can't_ be used for pthread_self(), since the pid is the _same_ > across all threads in a pthread environment. > > See? > > I re-iterate: > > - getpid() was used in some historical threading packages (maybe even > LinuxThreads) to get the thread ID thing. > > But this particular usage requires the old Linux behaviour of > returning separate threads ID's for separate threads. CLONE_THREAD > does not do that, and in particular the glibc caching _breaks_ any > such attempt even when you don't use CLONE_THREAD. > > pthreads() in modern libc sets CLONE_THREAD and then uses the > per-thread segment thing to identify threads. No getpid() anywhere. > > Ergo: getpid() caching may result in faster execution, but in this > case it's actively _wrong_, and breaks the app. It's easy to make > things go fast if you don't actually care about whether the end > result is correct or not. > > - getpid() is used in some silly benchmarks. > > But in this case caching getpid() just lies to the benchmark, and is > pointless. > > Ergo: getpid() caching results in higher scores, but the scores are > now meaningless, since they have nothing to do with system call speed > any more. > > So in both of these cases, the caching literally results in WRONG > behaviour. > > Can somebody actually find an application that doesn't fall into > either of the above two categories, and calls getpid() more than a > handful of times? > Well, not exactly sure about my reply, but let me try. The other day I was debugging some config problems with my qmail instalation and I ended up doing: # strace -p 4563 -f -F ... [pid 13097] read(3, "\347\374\375TBH~\342\233\337\220\302l\220\317\237\37\25"..., 32) = 32 [pid 13097] close(3) = 0 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getuid32() = 89 [pid 13097] getpid() = 13097 [pid 13097] time(NULL) = 1086497450 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] time(NULL) = 1086497450 [pid 13097] getpid() = 13097 [pid 13097] getpid() = 13097 [pid 13097] write(0, "\26\3\1\0J\2\0\0F\3\1@\302\242\2527j\266m4{\323>6\232\243"..., 1127) = 1127 [pid 13097] read(0, "\26\3\1\1\6", 5) = 5 ... where 4563 is a tcpserver process and 13097 is its child. The process was started as: tcpserver -s -n ssmtp.crt -p -v -R -x /etc/tcprules.d/tcp.smtp.cdb -c 40 -u 89 -g 89 0.0.0.0 465 /var/qmail/bin/qmail-smtpd mail.tar.bz /var/vpopmail/bin/vchkpw /bin/true No idea why are all those getpid() call there in the child... Looked at the code, but couldn't get it. Attaching tcpserver.c for reference. Again, sorry if unrelated. Kalin. -- ||///_ o ***************************** ||//'_/> WWW: http://ThinRope.net/ |||\/<" |||\\ ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^