posix_process_alive.cpp 551 B

1234567891011121314151617181920212223242526
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/posix/process.h>
  5. #include<__vic/throw_errno.h>
  6. #include<signal.h>
  7. #include<cerrno>
  8. namespace __vic { namespace posix {
  9. //----------------------------------------------------------------------------
  10. bool process_alive(pid_t pid)
  11. {
  12. if(::kill(pid, 0) == 0) return true;
  13. switch(int err = errno)
  14. {
  15. case EPERM: return true;
  16. case ESRCH: return false;
  17. default: throw_errno("kill", err);
  18. }
  19. }
  20. //----------------------------------------------------------------------------
  21. }} // namespace