plz help me out guys..i need to built a alarm in which we have to create a interrupt(or a simple printf) after particular point of time also to take care that program in which alarm is called should not terminate before that particular point of time
plz help me out guys..i need to built a alarm in which we have to create a interrupt(or a simple printf) after particular point of time also to take care that program in which alarm is called should not terminate before that particular point of time
Are you just supposed to have the program wait until a certain time, and then print a message? How about calling Sleep() (for Windows) or sleep() (for *nix) and then printing your message?
if we use sleep then the whole process will be sleeping until the particular point of time but my requirement is a timer has to run in the background without disturbing any process...
Sleep counts time for you - so the "timer is running in the background"...
Not whole process is sleeping - just the current thread
And Sleep does not disturbs other processes...
If you need the higher precision than the Sleep - you can use WaitForsingleObject on the current thread handle (in windows)
If Sleep is not good for you - explain better what do you want to achieve...
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
My requirement is,Code:Void Alarm(int time) { // code to create a interrupt } main() { //some code goes here Alarm(10); FnafterAlarm(); }
1)once the control reaches the Alarm function we have to give some i/p (time) and the alarm function have to start a timer inpendentally and the control has to come out immediately after giving i/p.
2)if suppose the control is in FnAfterAlarm() and the timer reaches it limit then it have to create that interrupt
3)Also program should not terminate before that interrupt by Alarm().
b4 that i am very weak in threads....
hope this time i am very clear abt my requirement,if it is not enough i am ready to explain better
Last edited by kky2k; 05-29-2007 at 11:45 PM.
What O/S are you doing this for?
Are you trying to recreate this?
http://www.scit.wlv.ac.uk/cgi-bin/mansec?2+alarm
If you're on Unix/Linux, you can simply fork() inside the Alarm() function and have the child sleep until the time has elapsed, and then call exit(). The parent meanwhile would return from the Alarm() function, do whatever it would like to do in other functions, and then call wait() for the child to finish. At that point the parent can terminate, too.
yes u r right i want to recreate that..is it possible to create that without using sleep()?
On windows you will need to CreateThread for this...
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
hi "vart" can u explain it further...
I can't think of a better way to do it than to either fork() or create a new thread and just have the child process/thread sleep.
Then again, maybe I just keep thinking about sleeping because I'm tired.
ok "macGyver" thanks for ur contribution...anway i am parallely googling to find the solution