shanecode / psutil

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

ppid should optionally be cached #321

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I use psutil in a watch-dog application.  This watch-dog checks for a change in 
ppid to 1.  

Since psutil caches the ppid value, the said watch-dog can't detect when a 
process isn't killed correctly and stuck with parent process id 1.

It would be nice to have access to a non-cached version of ppid.

Original issue reported on code.google.com by JeanLou....@gmail.com on 30 Aug 2012 at 1:41

GoogleCodeExporter commented 9 years ago
The reason why ppid is cached is because the parent is not supposed to be 
subject to change.
So I ask: how can you have a process whose parent is changing?
BTW, you can already skip the cached version and directly use:
p._platform_impl.get_process_ppid()

Original comment by g.rodola on 30 Aug 2012 at 6:15

GoogleCodeExporter commented 9 years ago
The parent can change: when you issue a kill on a process but some child 
process won't exit.  E.g. a bash script with some a chain of piped processes 
and 1+ do not respond do not exit on a broken pipe.  In this case, the process 
gets attached to process 1 (init).

It happens, not doubt about it.
--

Accessing private methods isn't very clean.

Original comment by JeanLou....@gmail.com on 30 Aug 2012 at 9:57

GoogleCodeExporter commented 9 years ago
What platform(s) are we talking about?
Can you produce a link where this is discussed? 
I've never heard of such a thing and couldn't find any reference about it.

That aside, checking for stuck processes this way sounds unreliable to me.
You might want to try Process.status or use Process.wait() right after you 
killed/terminated the process of interest.

Original comment by g.rodola on 30 Aug 2012 at 10:09

GoogleCodeExporter commented 9 years ago
Linux.
See 
http://stackoverflow.com/questions/356722/killing-a-defunct-process-on-unix-syst
em for more info.
"Wait" on a process that doesn't respond to kill is of no help.

Original comment by JeanLou....@gmail.com on 30 Aug 2012 at 10:17

GoogleCodeExporter commented 9 years ago
I'll be in US for a while, not sure when I'll be able to get back to this.

Original comment by g.rodola on 31 Aug 2012 at 1:45

GoogleCodeExporter commented 9 years ago
Fixed in revision 465f9dfca8c8.
The ppid is not only cached on Windows.

Original comment by g.rodola on 10 Apr 2013 at 7:21

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 11 Apr 2013 at 9:17

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago

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