How to track and calculate with datas in the background?

How can I track the alarm times in the background without constantly comparing them with the current time? How to get (and calculate) live data be retrieved continuously in the background (or when the phone is locked), for example heart rate data from HealthKit?

How to track and calculate with datas in the background?
 
 
Q