Some years late, here's a one-liner to find the PID of a command :
read -p "What is the name if the command to find PID of ? " pname ; jobs -l | grep $pname | awk '{ print "The command PID is "$2}
What it does :
Ask for the process name variable pname
list all jobs and search for $pname with grep
use awk to return the result legibly.
Easily amended to stop a process for example, by modifying the awk step and passing to bash
read -p "What is the name if the command to find PID of ? " pname ; jobs -l | grep $pname | awk '{ print "kill "$2} | bash
or non interactively for any process/command "foo" it's very succinct :
set pname=foo ;
jobs -l | grep $pname | awk '{ print "The command PID is "$2}
though note this assumes there is just one process named foo. In the unlikely event one were in that situation, one could add a test for number of answers, and if number greater than one, propose a list of process IDs
$$
may be parent PID inbash
:testfun() { echo "\$\$=$$ \$BASHPID=$BASHPID"; }; echo "my pid is $$"; testfun & wait