26#include <system_error>
32void redirect_stream_to_fd(
int fd,
int stream)
34 auto rc = ::dup2(fd, stream);
36 throw std::system_error(errno, std::system_category());
39void print_backtrace(std::ostream& out,
const std::string& line_prefix)
43 out << line_prefix << std::dec << std::setw(2) << frame.depth() <<
"@" << std::hex << std::setw(14) << frame.frame_pointer() <<
": "
44 << (frame.symbol().is_cxx() ? frame.symbol().demangled() : frame.symbol().raw()) << std::endl;
60 ChildProcess::Pipe
stdin_pipe{ChildProcess::Pipe::invalid()};
61 ChildProcess::Pipe
stdout_pipe{ChildProcess::Pipe::invalid()};
62 ChildProcess::Pipe
stderr_pipe{ChildProcess::Pipe::invalid()};
74 throw std::system_error(
errno, std::system_category());
94 }
catch(
const std::exception&
e)
96 std::cerr <<
"core::posix::fork(): An unhandled std::exception occurred in the child process:" << std::endl
97 <<
" what(): " <<
e.what() << std::endl;
101 std::cerr <<
"core::posix::fork(): An unhandled exception occurred in the child process." << std::endl;
133 throw std::system_error(
errno, std::system_category());
154 }
catch(
const std::exception&
e)
156 std::cerr <<
"core::posix::fork(): An unhandled std::exception occurred in the child process:" << std::endl
157 <<
" what(): " <<
e.what() << std::endl;
161 std::cerr <<
"core::posix::fork(): An unhandled exception occurred in the child process." << std::endl;
int main(int argc, char *argv[])
The Process class models a child process of this process.
The Frame class models an individual frame of a backtrace.
void visit_with_handler(const FrameHandler &handler)
visit_with_handler iterates the backtrace of the calling program, invoking the handler for every fram...
Status
The Status enum wrap's the posix exit status.
CORE_POSIX_DLL_PUBLIC ChildProcess vfork(const std::function< posix::exit::Status()> &main, const StandardStream &flags)
fork vforks a new process and executes the provided main function in the newly forked process.
Signal
The Signal enum collects the most common POSIX signals.
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.
StandardStream
The StandardStream enum wraps the POSIX standard streams.