How to find process id of current and sub shell in Linux ?

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”.

$BASHPID –> One of the Bash builtin Variable which prints Sub process id.
If there is no sub process created, it will simply show Bash parent process id.

 

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 ~]# 
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments