If the process is a child process and $BASHPID is not set, it is possible to query the ppid of a created child process of the running process. It might be a bit ugly, but it works. Example:
Wherever you are (on an interactive command line or in a script), and in the case you do NOT have access to $BASHPID, you can get access to your current shell pid with this :
bash -c 'echo $PPID'
where simple quotes are essential to prevent premature string interpretation (so as to be sure the interpretation occurs in the child process, not in the current one).
The principle is just to create a child process and ask for its parent pid, that is to say "myself".
This code is simpler than ps-based Joakim solution.