pid.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. BOOST_PROCESS_V2_BEGIN_NAMESPACE
  11. #if defined(GENERATING_DOCUMENTATION)
  12. //An integral type representing a process id.
  13. typedef implementation_defined pid_type;
  14. #else
  15. #if defined(BOOST_PROCESS_V2_WINDOWS)
  16. typedef unsigned long pid_type;
  17. #else
  18. typedef int pid_type;
  19. #endif
  20. #endif
  21. #if (defined(BOOST_PROCESS_V2_WINDOWS) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__sun))
  22. constexpr static pid_type root_pid = 0;
  23. #elif (defined(__APPLE__) && defined(__MACH__) || defined(__linux__) || defined(__ANDROID__) || defined(__OpenBSD__))
  24. constexpr static pid_type root_pid = 1;
  25. #endif
  26. /// Get the process id of the current process.
  27. BOOST_PROCESS_V2_DECL pid_type current_pid();
  28. /// List all available pids.
  29. BOOST_PROCESS_V2_DECL std::vector<pid_type> all_pids(boost::system::error_code & ec);
  30. /// List all available pids.
  31. BOOST_PROCESS_V2_DECL std::vector<pid_type> all_pids();
  32. // return parent pid of pid.
  33. BOOST_PROCESS_V2_DECL pid_type parent_pid(pid_type pid, boost::system::error_code & ec);
  34. // return parent pid of pid.
  35. BOOST_PROCESS_V2_DECL pid_type parent_pid(pid_type pid);
  36. // return child pids of pid.
  37. BOOST_PROCESS_V2_DECL std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec);
  38. // return child pids of pid.
  39. BOOST_PROCESS_V2_DECL std::vector<pid_type> child_pids(pid_type pid);
  40. BOOST_PROCESS_V2_END_NAMESPACE
  41. #if defined(BOOST_PROCESS_V2_HEADER_ONLY)
  42. #include <boost/process/v2/impl/pid.ipp>
  43. #endif
  44. #endif // BOOST_PROCESS_V2_PID_HPP