Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get a process by name and get a processes' descendants #242

Closed
giampaolo opened this issue May 23, 2014 · 8 comments
Closed

get a process by name and get a processes' descendants #242

giampaolo opened this issue May 23, 2014 · 8 comments

Comments

@giampaolo
Copy link
Owner

From [email protected] on January 19, 2012 11:39:21

    Here is a diff for two new additions to psutil.
    One is psutil.proc_by_name, which g.rodola actually wrote in issue 241 . I just 
    included it here in the diff, and changed it from returning an iterator to a list.

    The other is a get_lowest_descendants method on the Process object, which 
    fetches all descendants from a process, that don't have child processes 
    themselves.

    The use case that I have for this method is that I want to see what I am 
    currently doing in my terminal application. So my terminal will have a couple 
    of bash child processes (one for each tab), and each of those has child 
    processes as well, some being an ssh command into another machine, some being a 
    python interpreter in a certain folder, or a vi instance on a certain file, etc.

    With the get_lowest_descendants method I can easily fetch those descendants and 
    what they are doing.

Original issue: http://code.google.com/p/psutil/issues/detail?id=242

@giampaolo
Copy link
Owner Author

From [email protected] on January 19, 2012 02:39:37

and now with the diff attached :)

Attachment: init.py.diff

@giampaolo
Copy link
Owner Author

From g.rodola on January 19, 2012 05:33:39

> patch in attachment adds a get_lowest_descendants()
> method on the Process object, which fetches all 
> descendants from a process, that don't have 
> child processes themselves.

Mmm interesting.
I think I don't have a clear mind about this yet.
At first it seems kind of useful, on the other hand I'm not sure about its 
reliability.
Imagine this:

process A creates process B which creates process C

In normal circumstances your method would return A, B and C, but if B gets 
terminated in meantime you're gonna lose the reference to C and get only A in return.

Other than that, I think this would be better served by adding an extra 
argument to get_children() method:

>>> get_children(recursive=True)

...and make it return only B and C but not itself (A).


Also, it seems natural to make get_children() return an iterator rather than a list.
The same should be done for get_open_files(), get_connections() and 
get_threads() (I'll file a new ticket for that).


Jay, what do you think?

Status: WaitingForReview
Cc: [email protected]

@giampaolo
Copy link
Owner Author

From [email protected] on January 19, 2012 06:07:13

In your example where process A creates process B which creates process C, 
the code would only return process C, not B, since B has children.

Another option for my use case would then be 
>>> filter(lambda x: len(x.children)==0,get_children(recursive=True))

@giampaolo
Copy link
Owner Author

From g.rodola on April 07, 2012 08:38:10

This is now implemented in r1282 .
Please look at the docstring and let me know if with this you're able to cover 
your use case.

Status: Started

@giampaolo
Copy link
Owner Author

From g.rodola on April 08, 2012 05:37:10

Change recursion algorithm as r1283 .

@giampaolo
Copy link
Owner Author

From g.rodola on April 12, 2012 11:15:08

Status: FixedInSVN
Cc: [email protected]
Labels: Milestone-0.5.0 Usability

@giampaolo
Copy link
Owner Author

From g.rodola on June 27, 2012 11:54:03

0.5.0 is finally out. Closing out as fixed.

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 04:06:27

Updated csets after the SVN -> Mercurial migration: r1282 == revision 
19893ece7eff r1283 == revision 0e9fabea61e2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant