Detect a player that is nearest to a selected entity
Solution 1:
to kill the entity that is the closest one to the player you can do
/execute @p ~ ~ ~ /kill @e[type=!player,c=1]
in reverse, to kill the player that is the closest to an entity, you can do
/execute @e[yourEntityHere] ~ ~ ~ /kill @p
be aware that @p
only selects the closest, non-dead player that matches the given criteria and can't be used to select entities.