Reputation: 221
I need to test whether several .py scripts (all part of a much bigger program) work after updating python. The only thing I have is their path. Is there any intelligent way how to find out from which other scripts are these called? Brute-forece grepping wasn't as good aas I expected.
Upvotes: 1
Views: 551
Reputation: 221
I combined two things:
Thanks for the os.walk and os.getppid suggestion, however, I didn't want to write/use any additional code.
Upvotes: 0
Reputation: 56
Use os.getppid()
to get the parent PID from the process, and then you can grep for it or similar.
For example:
import os
import subprocess
ppid = os.getppid()
output = subprocess.check_output(['ps', str(ppid)])
print 'Some info about my parent process (%d):' % ppid
print output.strip().split('\n')[-1]
Upvotes: 1