I am making a timer for a game in c++. i fork a child process that sleeps for 60 seconds and then sends a signal (using RAISE function)"SIGCHLD" to the parent when its done. Upon sending the signal i have a while loop executed by my parent. Since the child and parent do not share address space, I cant just have the child process change a flag that will cause the loop to exit. And if i use vfork (which shares address space) then the parent will sleep along with the child. The only way i can make an exit condition for my parent is to catch the signal using "SIGNAL(SIG, function)" in the signal.h library. what it does is catches signal and sends you to the function you pass. Well it only lets you pass a void function with no parameters. So i made it edit a global variable in this function. Is there a better way to do this?
Look up setitimer() and have the parent use that to receive a SIGALRM when the timer expires instead of using a child process. Signal handlers can not do much ... setting a global variable that the parent can monitor during "normal" execution is fine.
If the parent is just nothing more than a typical game loop -- get input, update sprites, draw ad nauseum then alternatively you can just have the parent check the time each time through the loop and figure out if 60 seconds has elapsed.
thank you so much. One problem though that i would face if i did that. In my loop there is a "cin" and it will pause on that and wont be able to check if 60 seconds has elapsed in the loop. How can i make it so that when the timer goes off, it will interrupt the cin and say "times up"