process-cpp
3.0.0
A simple convenience library for handling processes in C++11.
|
Go to the documentation of this file.
21 #include <system_error>
28 const int read_fd = 0;
29 const int write_fd = 1;
35 throw std::system_error(errno, std::system_category());
40 fds[0] = ::dup(rhs.fds[0]);
41 fds[1] = ::dup(rhs.fds[1]);
54 fds[0] = ::dup(rhs.fds[0]);
55 fds[1] = ::dup(rhs.fds[1]);
57 counter = rhs.counter;
64 static const short empty_revents = 0;
65 pollfd poll_fd[1] = { { fds[write_fd], POLLOUT, empty_revents } };
68 if ((rc = ::poll(poll_fd, 1, duration.count())) < 0)
69 throw std::system_error(errno, std::system_category());
73 static const std::uint32_t value = 1;
74 if (
sizeof(value) != write(fds[write_fd], std::addressof(value),
sizeof(value)))
75 throw std::system_error(errno, std::system_category());
80 static const short empty_revents = 0;
81 pollfd poll_fd[1] = { { fds[read_fd], POLLIN, empty_revents } };
84 if ((rc = ::poll(poll_fd, 1, duration.count())) < 0)
85 throw std::system_error(errno, std::system_category());
89 std::uint32_t value = 0;
90 if (
sizeof(value) != read(fds[read_fd], std::addressof(value),
sizeof(value)))
91 throw std::system_error(errno, std::system_category());
94 throw std::system_error(errno, std::system_category());
configure_file(process-cpp.pc.in process-cpp.pc @ONLY) install(FILES $
A cross-process synchronization primitive that supports simple wait-condition-like scenarios.
cmake_build_type_lower if("${cmake_build_type_lower}" STREQUAL "debug") option(PROCESS_CPP_ENABLE_DOC_GENERATION_BY_DEFAULT "Generate package by default" OFF) else() option(PROCESS_CPP_ENABLE_DOC_GENERATION_BY_DEFAULT "Generate package by default" ON) endif() if(PROCESS_CPP_ENABLE_DOC_GENERATION) if($
add_library(process-cpp SHARED core/posix/backtrace.h core/posix/backtrace.cpp core/posix/child_process.cpp core/posix/exec.cpp core/posix/fork.cpp core/posix/process.cpp core/posix/process_group.cpp core/posix/signal.cpp core/posix/signalable.cpp core/posix/standard_stream.cpp core/posix/wait.cpp core/posix/this_process.cpp core/posix/linux/proc/process/oom_adj.cpp core/posix/linux/proc/process/oom_score.cpp core/posix/linux/proc/process/oom_score_adj.cpp core/posix/linux/proc/process/stat.cpp core/testing/cross_process_sync.cpp core/testing/fork_and_run.cpp) target_link_libraries(process-cpp $
option(PROCESS_CPP_ENABLE_DOC_GENERATION "Generate package documentation with doxygen" ON) string(TOLOWER "$
CrossProcessSync & operator=(const CrossProcessSync &rhs)
operator =, dup's the underlying fds.
CORE_POSIX_DLL_PUBLIC ChildProcess exec(const std::string &fn, const std::vector< std::string > &argv, const std::map< std::string, std::string > &env, const StandardStream &flags)
exec execve's the executable with the provided arguments and environment.
set(IS_ALL ALL) endif() find_package(Doxygen) if(DOXYGEN_FOUND) configure_file($
CORE_POSIX_DLL_PUBLIC ChildProcess fork(const std::function< posix::exit::Status()> &main, const StandardStream &flags)
fork forks a new process and executes the provided main function in the newly forked process.
void try_signal_ready_for(const std::chrono::milliseconds &duration)
Try to signal the other side that we are ready for at most duration milliseconds.
~CrossProcessSync() noexcept
Closes the underlying fds.
cmake_minimum_required(VERSION 2.8) project(process-cpp) find_package(Boost COMPONENTS iostreams system REQUIRED) find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) pkg_check_modules(PROPERTIES_CPP properties-cpp) set(CMAKE_MODULE_PATH $
set(GMOCK_INCLUDE_DIR "/usr/include/gmock/include" CACHE PATH "gmock source include directory") set(GMOCK_SOURCE_DIR "/usr/src/gmock" CACHE PATH "gmock source directory") set(GTEST_INCLUDE_DIR "$
Thrown if any of the *_for functions times out.
CrossProcessSync()
Constructs a new sync element.
std::uint32_t wait_for_signal_ready_for(const std::chrono::milliseconds &duration)
Wait for the other sides to signal readiness for at most duration milliseconds.
CORE_POSIX_DLL_PUBLIC ForkAndRunResult fork_and_run(const std::function< core::posix::exit::Status()> &service, const std::function< core::posix::exit::Status()> &client)
Forks two processes for both the service and the client.