pid.hpp 1.8 KB

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