daemon_control.h 908 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Base class for UNIX-daemons (implements process control)
  2. //
  3. // Platform: ISO C++ 98/11 - POSIX
  4. // $Id$
  5. //
  6. // (c) __vic 2013
  7. #ifndef __VIC_POSIX_DAEMON_CONTROL_H
  8. #define __VIC_POSIX_DAEMON_CONTROL_H
  9. #include<__vic/defs.h>
  10. #include<__vic/posix/pidfile.h>
  11. #include<exception>
  12. #include<string>
  13. namespace __vic { namespace posix {
  14. //////////////////////////////////////////////////////////////////////////////
  15. class daemon_control
  16. {
  17. pidfile pid_file;
  18. public:
  19. struct already_running : public std::exception
  20. {
  21. const char *what() const noexcept;
  22. };
  23. explicit daemon_control(std::string );
  24. void daemonize();
  25. // First arg's values: stop, kill, status
  26. static int control(const char * , const char * );
  27. static void stop_and_wait(const char * );
  28. };
  29. //////////////////////////////////////////////////////////////////////////////
  30. }} // namespace
  31. #endif // header guard