Yes people know when they are getting ready to stop the fight for life. Some who are linked close to God will know instinctively more so them a formal thought whether it is a person lying on the death bed or someone who is about to be run over.
I think in the case of lying on your death bed you have fought a good fight and now grow weary of the fight and give up submitting to death and as such you know your time is close.