Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the parent script's name?

Tags:

bash

path

parent

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 =)

like image 320
BlackLotus Avatar asked Feb 09 '14 19:02

BlackLotus


1 Answers

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
like image 78
Reinstate Monica Please Avatar answered Oct 13 '22 05:10

Reinstate Monica Please