diff options
author | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-04-11 12:58:33 +0200 |
---|---|---|
committer | Giampaolo Rodola' <g.rodola@gmail.com> | 2013-04-11 12:58:33 +0200 |
commit | 7e06d4b624d9c380a1e5238c17f764ae4c4c51aa (patch) | |
tree | 8464f3b3b427c54c172b228eddcf7a22b331ef3a | |
parent | caa0de2dffd4c3e3fcedd0e5afaacea5e153d838 (diff) | |
download | psutil-7e06d4b624d9c380a1e5238c17f764ae4c4c51aa.tar.gz |
Fix issue 356 - Process.parent: make parent's creation time <= self
-rw-r--r-- | CREDITS | 4 | ||||
-rw-r--r-- | HISTORY | 2 | ||||
-rw-r--r-- | psutil/__init__.py | 14 |
3 files changed, 17 insertions, 3 deletions
@@ -146,3 +146,7 @@ I: 323 N: André Oriani E: aoriani@gmail.com I: 361 + +N: clackwell +E: clackwell@gmail.com +I: 356 @@ -42,6 +42,8 @@ BUG FIXES kvm_open(3) not being called. (patch by Jean Sebastien) * #338: [Linux] disk_io_counters() fails to find some disks. * #353: [OSX] get_users() returns an empty list on OSX 10.8. + * #356: Process.parent now checks whether parent PID has been reused in which + case returns None. * #365: Process wait() and set_nice() methods should check PID has not been reused by another process. diff --git a/psutil/__init__.py b/psutil/__init__.py index c666eeb7..e6eff016 100644 --- a/psutil/__init__.py +++ b/psutil/__init__.py @@ -125,6 +125,7 @@ class Process(object): The only exceptions for which process identity is pre-emptively checked are: + - parent - get_children() - set_nice() - suspend() @@ -227,14 +228,18 @@ class Process(object): return retdict @property + @_assert_is_running def parent(self): - """Return the parent process as a Process object. If no parent - pid is known return None. + """Return the parent process as a Process object. + If no parent is known return None. """ ppid = self.ppid if ppid is not None: try: - return Process(ppid) + parent = Process(ppid) + if parent.create_time <= self.create_time: + return parent + # ...else ppid has been reused by another process except NoSuchProcess: pass @@ -252,6 +257,9 @@ class Process(object): # change to 1 (init) in case this process turns into a zombie: # https://code.google.com/p/psutil/issues/detail?id=321 # http://stackoverflow.com/questions/356722/ + + # XXX should we check creation time here rather than in + # Process.parent? if os.name == 'posix': return self._platform_impl.get_process_ppid() else: |