Results 1 to 4 of 4

Thread: Python - How to check for a running process?

  1. #1
    Join Date
    May 2008
    Beans
    1,029

    Python - How to check for a running process?

    I'm trying to figure out how to check and see if a program is already running, to keep from executing the program a second time.

    The program that I am trying to check is x11vnc, which is run from the command line.

  2. #2
    Join Date
    Dec 2007
    Location
    .
    Beans
    Hidden!
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Python - How to check for a running process?

    Quote Originally Posted by dodle View Post
    I'm trying to figure out how to check and see if a program is already running, to keep from executing the program a second time.

    The program that I am trying to check is x11vnc, which is run from the command line.
    Maybe there are better ways but this works for me:
    Code:
    import commands
    output = commands.getoutput('ps -A')
    if 'x11vnc' in output:
        print "ITS ALIVE!!!"

  3. #3
    Join Date
    May 2008
    Beans
    1,029

    Re: Python - How to check for a running process?

    Thanks, so far that works really well.

  4. #4
    Join Date
    Sep 2006
    Beans
    2,914

    Re: Python - How to check for a running process?

    if Python is not a must, just do it from the shell
    Code:
    # ps -A | awk '/x1nvc/{print "alive";exit}'
    alive

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •