nav_jan
nav_jan

Reputation: 2553

How to know the process id of the process which executes a given script?

I have a multiple process running at a time and only one of these process will execute a given shell script.

I do not have access to the source code of these processes, but I have access to the script which is getting called by one of the processes.

Is it possible to modify the script so that I know which process executes the script?

Upvotes: 0

Views: 819

Answers (2)

nav_jan
nav_jan

Reputation: 2553

Adding echo $PPID in the script works as suggested by @anubhav

Upvotes: 1

xoryouyou
xoryouyou

Reputation: 656

You can echo the variable '$$' which contains the PID.

then you can use lsof -p PID to find who is running your script and what else is opened.

Also you can use lsof <path/to/your/script.sh> to see which process is accessing your script.

Upvotes: 0

Related Questions