signaling threads by pid on linux

[email protected] (Al Tobey)
Newsgroups perl.ithreads
Organization Priority Health
Message-ID <[email protected]>
Not only is using pids for threads in linux not portable to other
unixes, it is likely not portable to newer linux kernels.  NPTL (Native
POSIX Threading Layer) makes using pids in place of tids less
straightforward.   This will likely be the default in all Linux
installations before too long, and has been in Redhat since 8.0.  I
believe Debian unstable is using it, and all of the Redhat derivatives
like Mandrake are, of course, using it.  I'm not entirely sure about
UnitedLinux, though I think it does use NPTL.  Slackware 9.X does not.

The point of my story: stop using pids for threads in Linux or you could
be bitten.  They no longer show up in ps -ef/ps aux by default.  It may
work for now, but I don't think it is at all guaranteed.

Perl on Fedora Core 1.0 (a.k.a. redhat 10) is 5.8.1.

>cat /etc/fedora-release
Fedora Core release 1 (Yarrow)
>uname -a
Linux linuxws1 2.6.0-test6 #3 Mon Sep 29 10:56:19 EDT 2003 i686 i686
i386 GNU/Linux

>cat /tmp/th.pl 
#!/usr/bin/perl -w
use threads;
sub foo {
   while (1) { sleep 1 }
}
for ( my $i=0; $i<100; $i++ ) {
    threads->create( \&foo );
}
sleep 300;

> perl /tmp/th.pl &
> ps -ef |grep '[t]h.pl'
tobeya    6329  4740  0 14:31 pts/2    00:00:01 perl th.pl
> cd /proc/6329/task
> ls
6329/  6330/  6331/  6332/  6333/  6334/  6335/  6336/  6337/  6338/ 
6339/
> ls 6339
cmdline  cwd@  environ  exe@  fd/  maps  mem  mounts  root@  stat 
statm  status  wchan

So, threads still have pids under 2.6 and NPTL, but they're not shown by
default because they're not really processes - they're threads.   You
can still get the same information about a thread you can a process via
/proc/<pid number>/tasks/<thread pid> but who knows how they'll change
that interface next time.

I may be crying wolf, but I thought I'd point this out to save people
trouble down the road.

-Al Tobey





** ** **  PRIVILEGED AND CONFIDENTIAL  ** ** **
This email transmission contains privileged and confidential information 
intended only for the use of the individual or entity named above.  Any 
unauthorized review, use, disclosure or distribution is prohibited and 
may be a violation of law.  If you are not the intended recipient or a 
person responsible for delivering this message to an intended recipient, 
please delete the email and immediately notify the sender via the email 
return address or mailto:[email protected].  Thank you.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.