Yes; but first fix your buggy program before fiddling with systemd.
MariusMatutiae is quite correct. You have a problem with your program. It deadlocks. Fiddling with systemd isn't the answer. At best, it's a distraction. Fix your program so that it isn't broken. Direct your energies at the right thing.
That said, other people are going to come here because of the question title, rather than the question proper. For their benefit, here's the answer to the title, ignoring the question proper:
Yes, systemd can monitor dæmons and automatically restart them if they stop talking. Not just any old dæmons, though. As mvp notes, there's no way to know that a dæmon has hung (in this universe, where the halting problem is undecidable, at least). Neither systemd nor any other computer program will ever be capable of deducing from scratch that some random program thrown at them has deadlocked, or gone into an infinite loop, or whatever. The best that you'll get here is detecting that a dæmon hasn't performed a regular "heartbeat" operation within a required timespan.
Dæmons that take advantage of systemd's watchdog capabilities, therefore, have to be written to speak a systemd-specific protocol, the sd_notify protocol. This complicates the dæmon code a tad. It's complicated further because dæmons should, if written properly, check whether they've been invoked with the watchdog function enabled, as well.
A dæmon that speaks this protocol to make use of systemd's watchdog capability …
- … must check for the
WATCHDOG_USEC environment variable;
- … must call sd_notify() continually and frequently, throughout its lifetime, with the
WATCHDOG=1 option set, at an interval of about
WATCHDOG_USEC/2 ("USEC" stands for microseconds) ;
- … must have
Type=notify set in its unit file;
- … should have
=all) set in its unit file;
- … must have
WatchdogSec=seconds set in its unit file.
- … must link with
If you want to know the details of coding this, after reading the manual, make sure that you go to the right StackExchange. This is SuperUser. StackOverflow is over there.
- Lennart Poettering. 2011-04-12. Watchdogs. Freedesktop.org.