Try this. If it returns a process id then you have the process running. Use your process name instead of firefox
.
# Python2
import commands
commands.getoutput('pgrep firefox')
As commands module is no longer in python 3x, We can receive the process id using subprocess
module here.
# Python3
import subprocess
process = subprocess.Popen('pgrep firefox', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
my_pid, err = process.communicate()
Here my_pid
will be process id
.