There's no way to know for sure whether a dog knows they're dying or not but I do believe that dogs do sense when it's their time to die due to illness or just old age.
I do know that most times dogs will sense that a person is dying and will try to be near that person during their death.
Most people also know that they're about to die so I'm sure dogs know that they're about to die as well.