Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a Linux/Unix Bash script know its own PID?

I have a script in Bash called Script.sh, and it needs to know its own PID (i.e. I need to get PID inside the Script.sh )

Any idea how to do this ?

like image 314
Debugger Avatar asked Mar 22 '10 15:03

Debugger


People also ask

How do I know if PID is running in shell script?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

Can a bash function call itself?

Functions in Bash also support recursion (the function can call itself). For example, F() { echo $1; F hello; sleep 1; } . A recursive function is a function that calls itself: recursive functions must have an exit condition, or they will spawn until the system exhausts a resource and crashes.

What is PID bash?

In bash , the PID of a shell script's subshell process is stored in a special variable called $$ . This variable is read-only, and you cannot modify it in a shell script. For example: #!/bin/bash echo "PID of this script: $$"


1 Answers

The variable $$ contains the PID.

like image 120
Paul Tomblin Avatar answered Oct 02 '22 15:10

Paul Tomblin