In this post we will look how to find process id of current process and any sub shell process id generated as a result of pipe “|” or function “()”.
To identify sub shell process id, we will use a special builtin “$BASHPID”.
Generating Sub process and printing its process id
### Current shell process id [root@ngelinux ~]# echo $$ 26271 ### Generate a sub process using ":" and then print its PID. [root@ngelinux ~]# : | echo -e "Parent Process id is $$ \nCurrent sub process id is $BASHPID " Parent Process id is 26271 Current sub process id is 26606 [root@ngelinux ~]#