user3193905
user3193905

Reputation:

How can i get the parent script's name?

I have a bash-script that is called by another script or process. So script/process A calls script B.

I have access to change script B and i want to know the name (and path, if possible) of the script/process A.

What do i need to write into script B to echo/outout me the name of script/process A?

pstree is no option for me :/

Thanks in advance =)

Upvotes: 6

Views: 2228

Answers (1)

Reinstate Monica Please
Reinstate Monica Please

Reputation: 11653

To get the parent pid

echo "$PPID" 

To get parent process path you can parse the full cmd

ps -o command= -p "$PPID" | awk '{print $1}'

Another option on most unix-based systems

awk '{print $1}'  /proc/"$PPID"/cmdline

Upvotes: 7

Related Questions