pid.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2022 Klemens D. Morgenstern
  2. // Copyright (c) 2022 Samuel Venable
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PROCESS_V2_PID_HPP
  7. #define BOOST_PROCESS_V2_PID_HPP
  8. #include <boost/process/v2/detail/config.hpp>
  9. #include <boost/process/v2/detail/throw_error.hpp>
  10. #include <vector>
  11. #include <memory>
  12. BOOST_PROCESS_V2_BEGIN_NAMESPACE
  13. #if defined(GENERATING_DOCUMENTATION)
  14. //An integral type representing a process id.
  15. typedef implementation_defined pid_type;
  16. #else
  17. #if defined(BOOST_PROCESS_V2_WINDOWS)
  18. typedef unsigned long pid_type;
  19. #else
  20. typedef int pid_type;
  21. #endif
  22. #endif
  23. #if (defined(BOOST_PROCESS_V2_WINDOWS) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__sun))
  24. constexpr static pid_type root_pid = 0;
  25. #elif (defined(__APPLE__) && defined(__MACH__) || defined(__linux__) || defined(__ANDROID__) || defined(__OpenBSD__))
  26. constexpr static pid_type root_pid = 1;
  27. #endif
  28. /// Get the process id of the current process.
  29. BOOST_PROCESS_V2_DECL pid_type current_pid();
  30. /// List all available pids.
  31. BOOST_PROCESS_V2_DECL std::vector<pid_type> all_pids(error_code & ec);
  32. /// List all available pids.
  33. BOOST_PROCESS_V2_DECL std::vector<pid_type> all_pids();
  34. // return parent pid of pid.
  35. BOOST_PROCESS_V2_DECL pid_type parent_pid(pid_type pid, error_code & ec);
  36. // return parent pid of pid.
  37. BOOST_PROCESS_V2_DECL pid_type parent_pid(pid_type pid);
  38. // return child pids of pid.
  39. BOOST_PROCESS_V2_DECL std::vector<pid_type> child_pids(pid_type pid, error_code & ec);
  40. // return child pids of pid.
  41. BOOST_PROCESS_V2_DECL std::vector<pid_type> child_pids(pid_type pid);
  42. BOOST_PROCESS_V2_END_NAMESPACE
  43. #endif // BOOST_PROCESS_V2_PID_HPP