How to find a process by pattern-matching one of it's environment variables

You can query the environment of a process with the ps command. Eg. ps eww <PID>. Using this technique you can find a process based on its environment. Eg. if you're interested in processes running on a specific X server with DISPLAY=:2.0, then you could use this:
ps axeww --no-headers -o pid,cmd | fgrep "DISPLAY=:2.0"
Of course the output of this command is pretty much unreadable, but with a little tweak we can get a nice listing of the selected processes:
pids=$(ps axeww --no-headers -o pid,cmd | fgrep "DISPLAY=:2.0") && test -n "${pids}" && ps jww $(echo "${pids}" | awk '{pids = pids " " $1} END { print pids }')