What is ps -p $$ command in Linux
The command ps -p $$
in Linux is used to display detailed information about the current shell process.
Let’s break down the command:
ps
: This stands for "process status". It's a command-line utility that provides information about the currently running processes, including their process identification numbers (PIDs).-p
: This is an option that tellsps
to select the processes with the listed PIDs. In this case, it's followed by$$
, which is a special variable in bash that represents the PID of the current shell. So,$$
gets replaced by the PID of the current shell.
So, ps -p $$
will display information about the current shell process.
Here’s an example of what the output might look like:
PID TTY TIME CMD
26344 pts/0 00:00:00 bash
In this output:
PID
is the process ID.TTY
is the terminal type.TIME
is the cumulative execution time.CMD
is the command that started the process.
What is $$ Variable in Linux
The `$$` in a shell script or command line represents the Process ID (PID) of the current shell.
When you open a new terminal window, it starts a new instance of a shell. Each shell has a unique PID. The `$$` variable is a built-in variable in bash (and many other shells) that holds the PID of the current shell.
For example, if you run `echo $$` in a terminal, it will print the PID of the current shell. This is useful in scripts where you might need to know the PID of the current shell, for example, to manage subprocesses or to report the PID of a process.
A Linux Shell Script Related To $PPID Variable
Read More
My YouTube Channel
More shell script videos and linux tutorials on my YouTube Channel.