• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

childprocess.h

Go to the documentation of this file.
00001 #ifndef WIBBLE_SYS_CHILDPROCESS_H
00002 #define WIBBLE_SYS_CHILDPROCESS_H
00003 
00004 /*
00005  * OO base class for process functions and child processes
00006  *
00007  * Copyright (C) 2003--2006  Enrico Zini <enrico@debian.org>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00022  */
00023 
00024 #include <sys/types.h>
00025 #include <wibble/exception.h>
00026 #include <wibble/sys/macros.h>
00027 
00028 struct rusage;
00029 
00030 namespace wibble {
00031 namespace sys {
00032 
00036 class ChildProcess
00037 {
00038 protected:
00039     pid_t _pid;
00040         int m_status;
00041         void waitError();
00042 
00046     // TODO: since the destructor is called twice (one in the parent and one in
00047     // the child), it could be useful to add a bool isChild() method to let the
00048     // destructor and other functions know where they are operating.  The value
00049     // returned can be set by ChildProcess::fork.
00050     virtual int main() = 0;
00051 
00052 public:
00053     ChildProcess() : _pid(-1) {}
00054     virtual ~ChildProcess() {}
00055 
00057     pid_t fork();
00058 
00062     pid_t forkAndRedirect(int* stdinfd = 0, int* stdoutfd = 0, int* stderrfd = 0);
00063 
00071     pid_t pid() const { return _pid; }
00072 
00076     int wait();
00077 
00078         bool running();
00079         int exitStatus();
00080         void waitForSuccess();
00081 
00085     int wait(struct rusage* ru);
00086 
00088     void kill(int signal);
00089 };
00090 
00091 }
00092 }
00093 
00094 // vim:set ts=4 sw=4:
00095 #endif

Generated on Sun Feb 17 2013 02:35:42 for wibble by  doxygen 1.7.1