Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 440
  • Last Modified:

Kylix Daemon. TTimer

I have a kylix daemon application that is basically a udpserver.
I need it to have some functionality like the TTimer component.
It needs to perform a certain action every 5 mins.
Do I make a child process and make it sleep for 5 mins ?
How do I catch the event when it wakes?
Any help is greatly appreciated. A source code example would be fantastic.
Thankyou. I am extremely urgent.
0
RickJ
Asked:
RickJ
  • 3
  • 2
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
mmm...have a look at this time loop example....

ftp://ftp.cncware.com/pub/fpc/daemon.pp
0
 
RickJAuthor Commented:
Thankyou for the link Ferruccio68.
I have something similar to this already.
To activate my function every 5 mins are you saying that I should set secs in this example to 5 ?
Is it practical to do this in the main processing loop or should I have some sort of child process within the main loop?

I hope this makes sense.


{ begin processing loop }
   If secs > 0 Then
   Repeat
      If bHup Then Begin
         {$I-}
         Close(fLog);
         IoResult;
         {$I+}
         NewLog;
         bHup := false;
      End;
      {----------------------}
      { Do your daemon stuff }
      GetTime(hr,mn,sc,sc100);
      Append(flog);
      Writeln(flog,'daemon code activated at ',hr:0,':',mn:0,':',sc:0);
      Close(fLog);
      { the following output goes to the bit bucket (/dev/null) }
      Writeln('daemon code activated at ',hr:0,':',mn:0,':',sc:0);
      {----------------------}
      If not bTerm Then
         { wait a while }
         Select(0,nil,nil,nil,secs);
   Until bTerm;
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
well....what is coded in the example is a loop that writes in a log file....

of course setting the secs value to your preferred it will be performed into that timing...
BTW the result is a kind of sleep until a particular condition or event happens.

--> Is it practical to do this in the main processing loop or should I have some sort of child process within the main loop?

It depends on what your main process have to do: Yes if it must only perform the action every 5 mins, but if you need to perform other actions in addition so the loop process must be performed by a child process ('cause the wait stuff freeze the process for a while)...

 
0
 
RickJAuthor Commented:
Thankyou Ferruccio68.
Sorry for the delay in replying.
How do I start a looping child process from within the main process?
Answer this and the points are yours.
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
well...usually the child process differs from the parent just for the PID...actually i'm pretty busy so i've no time to write a complete example but you can find a little kylix daemon's tutorial here http://www.pharos-comms.tele2.co.uk/free_downloads/DaemonsPart1.pdf or this C++ example here http://www.devhome.org/c/tutorials/daemon.html...
Also a couple of Kylix example in Borland Code Central (need login by registered user)...
Hope this help

F68 ;-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now