You can use psutil
to ask for the name of the process with id the parent process id:
import psutil
import os
ppid = os.getppid() # Get parent process id
psutil.Process(ppid).name() == "bash"
You can install psutil
with pip
command:
pip install psutil