baweaver / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Windows' PID re-use not considered in Process.ppid, Process.parent, at least in process_info.c:get_ppid() #356

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Looking at process_info.c, get_ppid() it seems that it does not consider PID 
reuse, because it does not check if the found process has a creation time 
smaller than or equal to the current process.

As a workaround: If process.parent returns a Process reference the creation 
time of that process should be checked to ensure that the parent process is 
older than or as old as the process (a sub-process can have the same creation 
timestamp as its parent process, IIRC what a colleague once reported):

def my_get_ppid(process):
    pp = process.parent
    if pp is not None:
        # Check if parent process is younger than
        # process:
        if pp.create_time > process.create_time:
            return None
    return pp.pid

def my_get_parent(process):
    if my_get_ppid(process) is not None:
        return process.parent
    return None

Possibly related issue: https://code.google.com/p/psutil/issues/detail?id=314

Original issue reported on code.google.com by clackw...@googlemail.com on 12 Mar 2013 at 4:07

GoogleCodeExporter commented 8 years ago
Fixed in revision 25aff1ab8dbc.
Thanks.

Original comment by g.rodola on 11 Apr 2013 at 10:59

GoogleCodeExporter commented 8 years ago

Original comment by g.rodola on 12 Apr 2013 at 6:21