FAQ
I have Python 2.6.6. I would like to get this output

ps -ef | grep 'fglgo csm'

into a list. What is the best way to do that? I've been reading the
documentation, and am lost.

Thank you.
cmn

Search Discussions

  • Emile van Sebille at Feb 9, 2011 at 7:15 pm
    On 2/9/2011 10:58 AM octopusgrabbus said...
    I have Python 2.6.6. I would like to get this output

    ps -ef | grep 'fglgo csm'

    into a list. What is the best way to do that? I've been reading the
    documentation, and am lost.

    Thank you.
    cmn
    commands.getoutput

    Emile
  • Dan Stromberg at Feb 9, 2011 at 9:34 pm

    On Wed, Feb 9, 2011 at 11:15 AM, Emile van Sebille wrote:
    On 2/9/2011 10:58 AM octopusgrabbus said...
    I have Python 2.6.6. I would like to get this output

    ps -ef | grep 'fglgo csm'

    into a list. What is the best way to do that? I've been reading the
    documentation, and am lost.

    Thank you.
    cmn
    commands.getoutput

    Emile
    Also, consider using "ps -eo pid,comm" (or similar) instead of ps -ef
    - it should be easier to parse that way.
  • Bsergean at Feb 11, 2011 at 12:26 am
    If you're on Linux you should

    * Have a look at the /proc/ filesystem, there's probably what you want
    there.

    Here's a small script that print all the pid/cmd from the process ran
    with your user.

    #!/usr/local/bin/python

    import os
    import re
    import stat
    from os.path import join

    for pid in (pid for pid in os.listdir('/proc') if re.match('\d',
    pid)):
    cmdline_fn = join('/proc', pid, 'cmdline')
    cmdline = open(cmdline_fn).read()
    uid = os.stat(cmdline_fn)[stat.ST_UID]

    if os.getuid() == uid:
    print pid, cmdline


    For a more cross-platform solution there's a module that does that (I
    forgot it's name but with some googling you might find it)



    On Feb 9, 1:34?pm, Dan Stromberg wrote:
    On Wed, Feb 9, 2011 at 11:15 AM, Emile van Sebille wrote:

    On 2/9/2011 10:58 AM octopusgrabbus said...
    I have Python 2.6.6. I would like to get this output
    ps -ef | grep 'fglgo csm'
    into a list. What is the best way to do that? I've been reading the
    documentation, and am lost.
    Thank you.
    cmn
    commands.getoutput
    Emile
    Also, consider using "ps -eo pid,comm" (or similar) instead of ps -ef
    - it should be easier to parse that way.
  • Dan Stromberg at Feb 11, 2011 at 1:06 am
    FWIW, Linux' /proc is very different from pretty much all other *ix's.
    I like Linux' design better, but it might be good to put the Linux
    /proc assumption in one place, in case you need to port to another *ix
    someday.
    On Thu, Feb 10, 2011 at 4:26 PM, bsergean wrote:
    If you're on Linux you should

    * Have a look at the /proc/ filesystem, there's probably what you want
    there.

    Here's a small script that print all the pid/cmd from the process ran
    with your user.

    #!/usr/local/bin/python

    import os
    import re
    import stat
    from os.path import join

    for pid in (pid for pid in os.listdir('/proc') if re.match('\d',
    pid)):
    ? ?cmdline_fn = join('/proc', pid, 'cmdline')
    ? ?cmdline = open(cmdline_fn).read()
    ? ?uid = os.stat(cmdline_fn)[stat.ST_UID]

    ? ?if os.getuid() == uid:
    ? ? ? ?print pid, cmdline


    For a more cross-platform solution there's a module that does that (I
    forgot it's name but with some googling you might find it)



    On Feb 9, 1:34?pm, Dan Stromberg wrote:
    On Wed, Feb 9, 2011 at 11:15 AM, Emile van Sebille wrote:

    On 2/9/2011 10:58 AM octopusgrabbus said...
    I have Python 2.6.6. I would like to get this output
    ps -ef | grep 'fglgo csm'
    into a list. What is the best way to do that? I've been reading the
    documentation, and am lost.
    Thank you.
    cmn
    commands.getoutput
    Emile
    Also, consider using "ps -eo pid,comm" (or similar) instead of ps -ef
    - it should be easier to parse that way.
    --
    http://mail.python.org/mailman/listinfo/python-list
  • James Mills at Feb 11, 2011 at 12:46 am

    On Thu, Feb 10, 2011 at 4:58 AM, octopusgrabbus wrote:
    I have Python 2.6.6. I would like to get this output

    ps -ef | grep 'fglgo csm'

    into a list. What is the best way to do that? I've been reading the
    documentation, and am lost.
    Have you checked out psutil (1) to see if it
    meets your needs ?

    cheers
    James

    1. http://pypi.python.org/pypi/psutil/0.2.0

    --
    -- James Mills
    --
    -- "Problems are solved by method"

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedFeb 9, '11 at 6:58p
activeFeb 11, '11 at 1:06a
posts6
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase