Check if a process is running or not on Windows?
You can not rely on lock files in Linux or Windows. I would just bite the bullet and iterate through all the running programs. I really do not believe it will be as "expensive" as you think. psutil is an excellent cross-platform python module cable of enumerating all the running programs on a system.
import psutil
"someProgram" in (p.name() for p in psutil.process_iter())
Checking if program is running programmatically
The module psutil can help you. To list all process runing use:
import psutil
print(psutil.pids()) # Print all pids
To access the process information, use:
p = psutil.Process(1245) # The pid of desired process
print(p.name()) # If the name is "python.exe" is called by python
print(p.cmdline()) # Is the command line this process has been called with
If you use psutil.pids()
on a for, you can verify all if this process uses python, like:
for pid in psutil.pids():
p = psutil.Process(pid)
if p.name() == "python.exe":
print("Called By Python:"+ str(p.cmdline())
The documentation of psutil is available on: https://pypi.python.org/pypi/psutil
EDIT 1
Supposing if the name of script is Pinger.py, you can use this function
def verification():
for pid in psutil.pids():
p = psutil.Process(pid)
if p.name() == "python.exe" and len(p.cmdline()) > 1 and "Pinger.py" in p.cmdline()[1]:
print ("running")
Related Topics
Key Error: None of [Int64Index...] Dtype='Int64] Are in the Columns
How to Check If a String Contains 2 of the Same Character
How to Get Elasticsearch to Perform an Exact Match Query
How to Split by Commas That Are Not Within Parentheses
How to Make Multiple Empty Lists in Python
Test a Function Called Twice in Python
How to Plot in Real-Time in a While Loop Using Matplotlib
Inserting a Python Datetime.Datetime Object into MySQL
Best Practices for Adding .Gitignore File for Python Projects
Check If a Python Script Is Already Running in Windows
Extract File Name from Read_Csv - Python
How to Replace Negative Numbers in Pandas Data Frame by Zero
Django Viewset Has Not Attribute 'Get_Extra_Actions'
Fastest Way to Compute Image Dataset Channel Wise Mean and Standard Deviation in Python
Numpy Import Throws Attributeerror: 'Module' Object Has No Attribute 'Core'
How to Hide Chrome Driver in Python
Extract Values Between Two Strings in a Text File Using Python