Reading the question closely, the OP asks
So, is there a way to find out the parent process (if this is the
correct term) of a cmd.exe within another cmd.exe?
This is different from the title, which should probably should have read "How can I determine my current cmd.exe's parent process"
Answering the question not the title, a very simple approach is to use AUTORUN.CMD. Since this run before every invocation of CMD, it can be as simple as:
SET /A LEVEL=%LEVEL+1
ECHO LEVEL = %LEVEL%
Caution AUTORUN.CMD, while it works as documented, it is defined per user and so is really only useful for non-critical things. Any other code which relies on AUTORUN.CMD, must handle the case where it does not exist.
For example, I use AUTORUN.CMD to append a star to the prompt, for each cmd nesting level:
PROMPT=%PROMPT%*$S
This is seen below.
Since CMD variables are local to the instance, when you exit cmd, the environment values from the "outer" cmd instance are used as can be seen here:
Microsoft Windows [Version 10.0.19044.1826]
(c) Microsoft Corporation. All rights reserved.
level = 1
T:\ * cmd
Microsoft Windows [Version 10.0.19044.1826]
(c) Microsoft Corporation. All rights reserved.
level = 2
T:\ * * exit
T:\ * echo %LEVEL%
1
T:\ *