Reputation: 3715
My question is simple - is it possible with the Python to check, which way application has been launched/spawned?
More information:
I got an application something.exe
and now I need to check if the something.exe
has been launched whether by the user or rather with some third party application running it as a child process.
Is it possible to check?
Upvotes: 3
Views: 452
Reputation: 3043
I tried on Windows using psutil this approach:
import psutil
def get_process_mode(process_name):
process_mode = None
plist = psutil.get_process_list()
for process in plist:
try:
if process.name == process_name:
if process.parent:
process_mode = "third party app"
else:
process_mode = "user launched"
break
except psutil.AccessDenied:
print "'%s' Process is not allowing us to check its parent!" % process
return process_mode
get_process_mode("something.exe")
But it didn't worked good in some cases...
Upvotes: 2
Reputation: 3514
With standard library it is not possible in windows. In Unix-like all processes (excepting init) have a parent.
import os
parent = os.getppid()
You can try to check os.environ
. Different methods to run can set slightly different environment or not set any variable.
Also look at psutil. It has many functions for process management.
Upvotes: 2