Timer in challenge problems

During my attempts at challenge problems I see that many times my programs finish in say around half a second though the time limit is 2 secondsish. In such cases I want to have my program run around 1.98 seconds and have a timer remind my program of this. I know that there is such a syscall in linux, but what is the suggested way to implement such a timer in my program?
Thanks in advance.
EDIT: I’m using c++14.

What language are you using?

Im using c++14.
------Just adding to reach 20 chars----