LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to use timer in redhat9 (https://www.linuxquestions.org/questions/programming-9/how-to-use-timer-in-redhat9-240841/)

wangjinyi 10-10-2004 01:12 AM

How to use timer in redhat9
 
I want do somthing periodically.
I want use timer but how to do it.
would you give me some idea or examples.
anything will be helpful.

mirradric 10-10-2004 02:12 AM

You can use cron to start your program.

Code:

man 5 crontab

wangjinyi 10-10-2004 02:32 AM

that's good and the program will be start periodically.

but I want do it in the program, that means the program will be start only once.

mirradric 10-10-2004 03:03 AM

Code:

man 3 sleep
This might interst you as well.
Code:

man daemon
of course i'm assuming that you use C

wangjinyi 10-10-2004 03:47 AM

I want use somthing like timers.
I give it a period and a function to invoke, then when the
time specified by period comes to the end, the function
will be invoked automatically.

I like this way ,because it make the program logic clear.

do you know How to achieve this purpose.

itsme86 10-10-2004 09:15 AM

man alarm

...and...

man setitimer

canavar_tayfun 10-10-2004 10:59 AM

you can use threads.for example "i=1 to 1000" block takes 1 seconds to complete so that in a thread function,you can control the value (it is i) if equals to 1000,if equals to 1000 you can start a code block you want.
i actually didnt tried this example cos i just learned threads.but i think it will work ; ).(and also i will try by now : )

mirradric 10-10-2004 11:41 AM

Quote:

Originally posted by canavar_tayfun
you can use threads.for example "i=1 to 1000" block takes 1 seconds to complete so that in a thread function,you can control the value (it is i) if equals to 1000,if equals to 1000 you can start a code block you want.
i actually didnt tried this example cos i just learned threads.but i think it will work ; ).(and also i will try by now : )

Are you suggesting busy waiting (or whatever the term is)? This will eat up cpu even as it does nothing. Doing sleep and alarm are less expensive.


All times are GMT -5. The time now is 05:47 AM.