I need to find a right way to prevent two running instances of my (Python) program. I am currently using the following method.
On Windows,
os.popen('wmic process get caption,processid | findstr `programname.exe`')
On Linux,
os.popen('ps x | grep `programname`')
It seems to work fine for now. Is this method correct? Can someone suggest to me a better way?
edit: Thanks for the reply guys, Is anything wrong with the above methods? I tried the pid file way for linux. What if the pid file gets deleted somehow?