Setting up timer in linux

Hi! I need to write a program that will be running under Linux. The program should check a database once a day and if some criteria are met, it needs to trigger some action. The analog of the similar function in Windows is SetTimer() function – you supply a time interval and a function that will be called. How can I implement the same thing in Linux? The program should be running as a background process? Thx
izloch2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duncan RoeSoftware DeveloperCommented:
You can run the program once a day from cron - man crontab for more on this approach.
Or are you saying the program runs all the time but has to do this task once a day? There's lots of ways of doing that too - post again if that's what you need.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
izloch2Author Commented:
thank you! and what are the other ways?
Duncan RoeSoftware DeveloperCommented:
You can use alarm() and a signal handler. Or gettimeofday() in the main despatcher loop (if your program is structured that way) (i.e. use in conjunction with poll() / select() to set a max timeout value). Or run a separate thread which notifies a semaphore. You always end up calling gettimeofday() and scheduling how long from now to call the function.
Separate program from cron is simplest though.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

ahoffmannCommented:
the general way in Unix would be a script (or program) called by cron
Artysystem administratorCommented:
I aggree with ahoffman, the better way is to use cron.
Duncan RoeSoftware DeveloperCommented:
ahoffman, Nopius: if you look back you will see I suggested cron first up. However izloch2 then asked "what are the other ways" which I took to possibly mean he has this program running 24/7 and it has to do this task once a day, so I gave him some options.
Now I come to think of it, even in that scenario his program could be checking every minute or so for a file to exist: the file could be created by "touch" in a cron job then the program would do the business and rm the file.
ahoffmannCommented:
duncan_roe, my comment was meant as Cc: to your first one ;-)

> ..  asked "what are the other ways" ..
hmm, without providing more information *why* there is a need for something else than cron, it's useless to guess and give hints for reenventing the wheel.
In Unix/Linux you don't need to write program for such simple things like doing something every n whatever, it's still there: cron (a bit rusty, 30 years or so, but still working perfect :-))
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.