Showing posts with label bashpid. Show all posts
Showing posts with label bashpid. Show all posts

Tuesday, March 14, 2017

How to find PID of the current working shell in linux ?

Using Following methods u can get the  PID of shell in linux.

Method 1:

echo $$
Example:

dev@linuxforfreshers.com:~$ echo $$
29215

Where $$  is the PID of the current shell.

Method 2:

dev@linuxforfreshers.com:~$ ps -p $$
  PID TTY          TIME CMD
29215 pts/40   00:00:00 bash

Or

dev@linuxforfreshers.com:~$ ps -p $$ | awk '{ print $1 }'
PID
29215


Method 3:
It will give all the shell’s PID numbers.

Example:

dev@linuxforfreshers.com:~$ sudo pidof /bin/bash
31396 29248 29215 27940 15796 15764

Method 4:
Using BASHPID

Example:

dev@linuxforfreshers.com:~$ echo $BASHPID
29215