Subj : Re: Linux MultiTherad To : comp.programming.threads From : Joe Seigh Date : Tue Aug 02 2005 07:42 am Gio67 wrote: > "AlterX" ha scritto nel messaggio > news:dclfkd$gi8$1@newsreader.mailgate.org... > >>Gio67 wrote: >> >>>HI, I'm developing a multithreading apllication in C using the pthread >>>library. >>>When a new thread i started , the Linux OS creates a new process, >> >>No... crate a new thread! >> >>and I >> >>>need to know wich is the pid of the new thread. >>>How can I do to know the pid ? There is an API ? >> >> >>How you create a thread without use pthread_create that return >>a thread id!??! >> >>you are mistake!!! > > > When I use a pthread_create() to create a thread I have the threadID, but if > I look for in the directory //proc/processpid/task/ I found a new directory > with a id that is different from the treadID returned by pthread_create(). > Why ? > > Those are kernel thread ids. They look like processes but they aren't really. Some stuff that requires process ids may appear to work or at least not give an error with the kernel thread ids but it's undefined behavior and it's probably not a good idea to depend on it. gettid() will get you the kernel id for the current thread. Except there's no gettid(). You need to use syscall(SYS_gettid). Given that, there doesn't appear to be much useful thread information in /proc//task/. It's mostly just process level info. Nobody has gotten around to putting useful thread information in /proc just yet. -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .