How to find the process id for the app instance created by "open" command
Similar question on StackOverflow

If you're programmatically doing this, one way to get the opened app's pid (subsequently using it to kill the process) is to get the grep the output of ps 
aux passing it the application's name. 

ps aux | grep -v grep | grep -I &lt;AppName&gt; | sort -rn | head -1 | awk '{print $2}'


Basically, pipe the output of the ps aux command through grep and sort it based on the value of the start time column.

As pointed by @user3439894 below, there's an easier way without the above rigmarole.

pgrep -nx Safari


returns the PID of the last opened instance of Safari and 

pkill -nx Safari


kills the last opened instance of Safari.