Daemon for Linux QT applications

Source: Internet
Author: User
Daemon for Linux QT applications

Requirement: when we want to restart the application immediately after it is accidentally closed or aborted, we need the daemon to help.
P.s.: no virus, no virus ......

Implementation Scheme

1. Start the daemon first
2. Load and start the QT application in the daemon. In this example, the QT Application name is MyApp.

Special note

1. Start the QT application on the PC:
Execle ("./MyApp", "", null, Environ );

2. During my experiment on the arm board, the above statements cannot be executed normally and need to be further written. At the same time, the embedded Linux QT does not support X11 and qws is required:
Execle ("./MyApp", "./MyApp", "-qws", null, Environ );

Reference Code

#include <stdlib.h>#include <string.h>#include <unistd.h>extern char **environ;enum{    START = 0,    WAIT,    STOPPING,};int main(int argc, char **argv){    int status = 0, mode = START;    pid_t pid ;    while(1)    {        switch(mode)        {            case START:                pid = fork();                if(!pid){                    execle("./myApp","",NULL , environ);                    //execle("./myApp","./myApp","-qws",NULL,environ);                }                if(pid > 0)                    mode = WAIT;                break;            case WAIT:                if(waitpid(pid, &status, 0) < 0)                {                    mode = START;                    break;                }                else if(WIFSIGNALED(status)||WIFSTOPPED(status)||WIFEXITED(status))                {                    mode = START;                }else{                    mode = WAIT;                }                break;            default:                break;        }    }    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.