When my grandfather was dying of cancer, his dog (jack russel X) whimpered to be let onto the bed. We let her on and she nuzzled into him. He became more relaxed and it seemed to relieve a little. After a few hours we put her down to take her to let her outside for a wee break and she got under his bed and wouldn't leave him until his breathing stopped. I think they know, human or animal, instinctively if something will or has happened. She was a bit depressed after he passed but my Aunty took her in to her house and she made friends with a cat and was like a different dog.