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 ?
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.
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.
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: $$"
The variable $$
contains the PID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With