Linux Tip #2: Get your PID with $$

“$$” is a useful Linux variable you could use in your script to get it’s PID. The “$$” variable always holds the PID of the executing process.

Why do you need it? Maybe to check if the script is already running? This is what I normally use it for.

Sample Script;

#!/bin/bash
echo "My PID is $$"
sleep 2

Sample Output;

[root@keke ~]# ./test1.sh
My PID is 8909

Leave a Reply

© 2008-2009 The Danesh Project
Powered by Wordpress and made by Guerrilla. Best viewed in Mozilla Firefox