Question

I'm running some C++ code (8 independent processes running on Ubuntu with 8 cores).

I'm launching the C processes using python:

def runC():
    numThreads = multiprocessing.cpu_count()
    threads = []
    for i in range(numThreads):
        args = ("./cprogram", arg1,arg2,arg3)
        popen = subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE)
        threads.append(popen)

    for t in threads:
       t.wait()
       output = t.stdout.read()
       err = t.stderr.read()
       if len(output) > 0:
          print "output: " + output
       if len(err) > 0:
          print "err: " + err

I keep getting "defunct" processes. What does that mean? Why did this happen to me?

Was it helpful?

Solution

Turns out it's the t.wait() that is causing the zombie process. Depending on the order that the jobs finish, there will be some in a zombie state until the t.wait() gets around to them. It's not really a problem, which is what I wanted to be sure of.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top