Tell me about space probes

I’ve always had the curiosity and have never heard much about what happens to a space probe that leads to it’s demise.Say it lands on Mars…after a few weeks or months the signal disappears.Do the bateries run out? Doesn’t it run on solar energy? Why do systems shut down so soon while I have read that other space probes such as Viking last for years? The Pathfinder only ran for a couple of months.:confused:
Thanks in advance