On Sunday 14 August 2005 16:14, Tristan Wibberley wrote: > I wrote: > >>I believe, from Linux's PoV, that a thread doesn't have a parent. All > >>threads in a process are equal. A thread's stack is just an area of > > > Mulyadi Santosa wrote: > > Are you sure about this Tristan? > > Not totally, no :) > > > IMHO every process has a parent, even > > it is a thread created on NPTL environment. Perhaps you got this > > impression since each thread has same pid? > > I remember reading a request from Linus Torvalds on lkml that the kernel > support for threads that NPTL would use should not treat any thread of a > process differently to any other, so any threads can die, and any one of > them can be the last. I meant that I thought a thread doesn't become the > parent of one that it creates (that they both have the same parent - the > process that was the parent of the first one). I admit I don't know the > details. In Linux a thread is viewed as a common process, different from the others. I means that each thread have a different pid. The way you can recognize threads is by controlling the memory descriptor. For example, if you want to know if a process is a thread, you have to control if its memory descriptor is shared with TWO other processes in the system having TWO different pids. To better explain this concept, I'll use an example. Suppose we are executing a process with pid 100. At any point, this process create a thread. The system creates a new process sharing resource with process 100. (for sake of simplicity, I suppose its pid is 101). The created thread is not the one created by process 100 but is the so called THREAD MANAGER. The thread manager creates a new thread (pid 102) with which shares the meomry descriptor and other resources. In other word, we have this situation: 100 (the process initially executing) | | 101 (the thread manager) | | 102 (the thread created) Now, suppose that the process 100 creates three threads. The situation changes: 100 (the process initially executing) | | 101 (the thread manager) / | \ / | \ 102 103 104 (the threads created) As you can see, threads 102 103 and 104 are sons of 101 while 101 is son of 100. Also, all the processes (from 100 to 104) share the same descriptor. Furthermore, the threads share also other resources, like terminal, files and so on (but they can create new file, access new tty, ....) The thread manager is created to better manage some tasks directed to all of threads created. An example is the signals directed to the thread. I ignore the way it manages the signal, perhaps it redirect a signal to the correct thread or to all of them. But, I'm really sure that a thread can receive a signal that the other threads don't receive. This is due, perhaps, to the different pid assigned to them. I hope I've explained clearly it. Vincenzo Mallozzi. ___________________________________ Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB http://mail.yahoo.it -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/