Subj : process vs. thread ids on linux To : comp.programming.threads From : jpknott@gmail.com Date : Thu Jun 02 2005 10:59 am I've stumbled across something that violates some of my basic notions about posix threads and process ids... Hopefully somebody will be able to set me straight. This is on a Redhat ES box, by the way, running a 2.4.21 kernel build. I have been under the impression that when you start a new thread (using pthread_create), it 'inherits' the pid of the 'parent' process. This would seem to be verified by calling getpid()... If I call this inside the new thread, it returns the same value as the original process. Indeed, if I create 10 threads within a process, getpid() returns the same pid for all of them. However, as I was reading the man page for the 'ps' command, I discovered the -m option, which purports to allow you to display 'all threads'. But if I do a 'ps -am', what I am apparently seeing is that each thread has a different, unique pid! For example, here I have a process called ttest. The original process has a pid of 19103. It spawns 10 threads. In my debugging logs, each thread reports a pid of 19103 (as returned from getpid()). However, a ps -am gives me this: 19103 pts/2 00:00:00 ttest 19104 pts/2 00:00:00 ttest 19105 pts/2 00:00:00 ttest 19106 pts/2 00:00:00 ttest 19107 pts/2 00:00:00 ttest 19108 pts/2 00:00:00 ttest 19109 pts/2 00:00:00 ttest 19110 pts/2 00:00:00 ttest 19111 pts/2 00:00:00 ttest 19112 pts/2 00:00:00 ttest 19113 pts/2 00:00:00 ttest So, what is going on here? If the kernel is indeed assigning a new pid to each thread, how can I get to that id (since getpid() doesn't work). Why doesn't getpid() work, anyway? And can I then use these pids to send signals directly to a particular thread (which I was under the impression was not possible)? .