CMDaemon Class Reference

Daemonizing programs. More...

Public Member Functions

 CMDaemon (int priority)
 ~CMDaemon ()

Detailed Description

Header for easy control of the daemonize process.

Author:
Miguel Ángel Vílchez López 2008 <sacra@openmatica.es>

Codigo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Codigo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.


Constructor & Destructor Documentation

CMDaemon::CMDaemon ( int  priority  ) 

Constructor.

Parameters:
[in] priority The priority for the new process, from -19(highest) to 20(lowest).

00031 {
00032   pid_t pid,sid;
00033 
00034   pid=fork();
00035   if(pid<0)
00036   {
00037     exit(EXIT_FAILURE);
00038   }
00039   
00040   //Exit from process father(original)
00041   if(pid>0)
00042   { exit(EXIT_SUCCESS); }
00043 
00044   if((sid=setsid())<0)
00045   {
00046     exit(EXIT_FAILURE);
00047   }
00048 
00049   close(STDIN_FILENO);
00050   close(STDOUT_FILENO);
00051   close(STDERR_FILENO);
00052   
00053   if(setpriority(sid,sid,priority)<0)
00054   {
00055     exit(EXIT_FAILURE);
00056   }
00057     
00058 }

CMDaemon::~CMDaemon (  ) 

Destructor.

00061 {
00062 }

 All Data Structures Functions Variables
Generated on Mon Sep 12 07:59:09 2011 for API MokArdu by  doxygen 1.6.3