This post covers getting the PID of a process by name with and without the sysutils/psmisc port.
Just use pgrep.
The following example uses pgrep in a script.
The easy way is to install the sysutils/psmisc port and use the pidof command.
The following can be used to get the information on all of the processes matching a name.
The following can be used to get the PIDs of all processes matching a name.
Something like the following can be used for control flow in a shell script.
The -qs flags suppress grep output.