Get thread pid

Ove Svensson ove.svensson at jeppesen.com
Fri Jan 30 12:00:31 CET 2009


Alejandro <alejandro.weinstein at gmail.com> writes:

> Hi:
>
> I have Python program running under Linux, that create several
> threads, and I want to now the corresponding PID of the threads.
>
> In each of the threads I have
>
> def run(self):
>     pid = os.getpid()
>     logger.critical('process ID: %s', pid)
>
> However, the reported PID is the father number, not the PID of the new
> thread. Is there a way to get the PID of the thread?

Pid is a process identifier. Threads are not processes. All your threads
execute within the context if a single process, hence they should have
the same pid. Threads may have a thread id but it is not the same as the
pid.



More information about the Python-list mailing list