Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Daemon.h
Go to the documentation of this file.
1 #ifndef Protium_Daemon_h_
2 #define Protium_Daemon_h_
3 
4 namespace Protium{
5  namespace Threads{
6 
7 
8  class Daemon{
9  private:
10  pid_t pid;
11  pid_t sid;
12  public:
13  Daemon(){
14  pid=0;
15  }
16 
17  void start(){
18 
19  pid=fork();
20  }
21 
22  bool isGood(){
23  return (pid!=-1) && (pid!=0);
24  }
25 
27  exit(EXIT_SUCCESS);
28  }
29 
30  void setFileMask(){
31  umask(0);
32  }
33  void setSID(){
34  sid=setsid();
35  if(sid<0)
36  exit(EXIT_FAILURE);
37  }
38 
39  void setToRootFile(){
40  if( chdir("/")<0){
41  exit(EXIT_FAILURE);
42  }
43  }
44 
46  close(STDIN_FILENO);
47  close(STDOUT_FILENO);
48  close(STDERR_FILENO);
49  }
50 
51  void loop(){
52 
53  //schedule tasks and whatnot
54  }
55  };
56  }
57 }
58 
59 
60 #endif //File Guardian
void closeFileDescriptors()
Definition: Daemon.h:45