Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Developing a Daemon for Mac with Qt and C++
Forum Updated to NodeBB v4.3 + New Features

Developing a Daemon for Mac with Qt and C++

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 960 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    coderqueen
    wrote on last edited by
    #1

    Hi,

    I am trying to develop a dummy daemon for Mac OSX which should launch on startup and should support 'Stop,Resume, Pause'. For now, I have developed a code which is simply opening a text file and logging some data on it when the service starts. Unsure on how to stop it. Any advice on the best approach possible would be appreciated. Here is a little snippet.

    @
    void AppService::start()
    {
    try
    {
    QCoreApplication *app= application();
    qDebug()<<"Service has started!";
    qDebug()<< app->applicationDirPath();

        FILE *t;
        pid_t pid=0;
        pid_t sid=0;
        pid=fork();
        if (pid < 0) {
                exit(1);
        }
        if(pid>0)
        {
            std::cout<<"Service has started!";
            exit(0);
        }
    
        umask(0);
        sid=setsid();
        if(sid <0)
        {
            exit(1);
        }
    
        chdir("/");
        t=fopen&#40;"/Users/gecdelivery/projectfile/logfile.txt","w+"&#41;;
    
    
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);
    
        while(1){
        sleep(1);
        fprintf(t,"Service is running!\t Time %s\n",dt);
        fflush(t);
    }
    fclose(t);
    
    
    }
    

    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved