c++ - Linux Daemon not working -
I created a daemon for Linux in C ++, however, the child process is not doing anything. Once it reaches the (pid & gt; 0) statement, everything is closing the code for Daemon.Start () as follows:
// Process ID and session ID Pid_t pid, sid; // Close the original process pid = fork (); If (PID & lt; 0) exit (EXIT_FAILURE); // If PID is good, then exit the parent process (PID & gt; 0) (EXIT_SUCCESS); // Change the file mode umask mode (0); // Create a new SID for the hair process sid = setsid (); If (SID & lt; 0) {exit (EXIT_FAILURE); } // Change the current working directory if ((chdir ("/")) <0} {// Exit Exit Failure (EXIT_FAILURE); } // close the standard file descriptor (STDIN_FILENO); Close (STDOUT_FILENO); Close (STDERR_FILENO); // Main Loop Globals :: Logarre ("Service began."); While (true) / service work globals :: logarrier ("service is working."); If (! System Configuration :: IsFirstRun () & System Configuration :: GetMediaUpdateReady ()) {SyncServer (); } Sleep (System Configuration :: GetServerConnectionFrequency ()); // Wait 30 seconds} Exit (EXIT_SUCCESS); Any help would be great! :)
I'm pretty sure that your child's process is either sid & lt; 0 or chdir ("/") & lt; 0 If the statement tells you what is the problem before writing stderr in these cases: // Create a new SID for the hair process sid = setid (); If (sid To get you wrong and strerror, & lt; Errno.h & gt; and & lt; String.h & gt; The need to include is defined (respectively). Regards
Comments
Post a Comment