program - like deamon do something interval

Discussion in 'Mac Programming' started by mehdies, Oct 2, 2012.

  1. mehdies, Oct 2, 2012
    Last edited: Oct 2, 2012

    mehdies macrumors member

    Joined:
    Jun 10, 2012
    #1
    hi guys

    I want to write program that work like daemon and do something in every second for example.and startup in system boot.could you help me?

    my program overview :

    Code:
    #import <Cocoa/Cocoa.h>
    
    func1()
    { 
    .....
    }
    
    func2()
    {
    ....
    }
    
    func3()
    {
    ....
    }
    
    int main()
    {
    func1();
    func2();
    func3(); /// This function must be execute interval - every second for example
    }
    I don't know must be use launctl with .plist file?
    Thanks
     
  2. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #2
    It seems like youre asking for for a launchctl script that runs a specific function inside if your program. I think that you will find this is not possible.

    What you should instead do, is move everything that would be considered 'setup' into a single place and wrap it in a check that determines if it needs setup. Usually the existence of a file, or a key-value pair in a plist for example.

    Thus you can run the program on an interval and it will just skip the functions that don't need to be run.
     

Share This Page