I have a script in bash called Script.sh, and i need to know his own PID ( i need to get PID inside the Script.sh )
Any clues to realize this ?
Regards,
Debugger
I have a script in bash called Script.sh, and i need to know his own PID ( i need to get PID inside the Script.sh )
Any clues to realize this ?
Regards,
Debugger
use $BASHPID
or $$
See the manual for more information, including differences between the two.
In addition to the example given in the Advanced Bash Scripting Guide referenced by Jefromi, these examples show how pipes create subshells:
$ echo $$ $BASHPID | cat -
11656 31528
$ echo $$ $BASHPID
11656 11656
$ echo $$ | while read line; do echo $line $$ $BASHPID; done
11656 11656 31497
$ while read line; do echo $line $$ $BASHPID; done <<< $$
11656 11656 11656