1

This simple Python program :

import threading
import time
import os

def run_test():

    print("run_test pid : " + str(os.getpid()))

    while True:
        time.sleep(100)

print("main pid : " + str(os.getpid()))
thread1 = threading.Thread(target=run_test)
thread1.start()

Starts multiple processes according to htop:

enter image description here

With PIDs 12004 and 12040.

However, there doesn't appear to be any point in the program where the second process is created.

Where does the second process come from ?

Tim Peters
  • 67,464
  • 13
  • 126
  • 132
Kalessar
  • 293
  • 5
  • 9
  • Which version of Python are you running? The code only shows one process when I run it on 2.7.10 – l'L'l Jul 23 '16 at 17:11
  • I'm running Python3.5 – Kalessar Jul 23 '16 at 17:13
  • This process runs forever... sure you don't have an old one running along with the new one? – tdelaney Jul 23 '16 at 17:13
  • If you haven't tried already, i would kill all of the processes in question and test it again... – l'L'l Jul 23 '16 at 17:15
  • yep, pretty damn sure – Kalessar Jul 23 '16 at 17:15
  • How about getting the process tree or at least the ppid, say, `ps xao pid,ppid,pgid,sid,comm`. Also, ctrl-c the program and restart it. Is the 12004 process still there? ... and cut and paste to post so we don't have to squint at the screenshot. – tdelaney Jul 23 '16 at 17:21
  • 1
    Apparently it is due to the fact that vanilla htop doesn't distinguish between process identifiers and thread identifiers without activating options ( source : my roommate ) – Kalessar Jul 23 '16 at 17:38
  • Yup! @Kalessar nailed it. See here: http://unix.stackexchange.com/questions/10362/why-does-htop-show-more-process-than-ps – Tim Peters Jul 23 '16 at 18:22

0 Answers0