Skip to content

Instantly share code, notes, and snippets.

@chomy
Created March 8, 2014 08:06
Show Gist options
  • Select an option

  • Save chomy/9427081 to your computer and use it in GitHub Desktop.

Select an option

Save chomy/9427081 to your computer and use it in GitHub Desktop.
template of daemon with Qt4
#include <qapplication.h>
#include <signal.h>
#include <unistd.h>
using namespace std;
void init_sig()
{
auto handler = [](int sig){
switch(sig){
case SIGHUP:
case SIGTERM:
QCoreApplication::exit();
}
};
signal(SIGCHLD,SIG_IGN);
signal(SIGTSTP,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
signal(SIGTTIN,SIG_IGN);
signal(SIGHUP,handler);
signal(SIGTERM,handler);
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
init_sig();
daemon(0,0);
// your code here
return app.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment