13 #ifndef __STOUT_OS_LINUX_HPP__
14 #define __STOUT_OS_LINUX_HPP__
18 #error "stout/os/linux.hpp is only available on Linux systems."
22 #include <sys/types.h>
45 const lambda::function<int()>* func =
46 static_cast<const lambda::function<int()>*
> (_func);
73 explicit Stack(
size_t size_) : size(size_) {}
80 int flags = MAP_PRIVATE | MAP_ANONYMOUS;
82 #if defined(MAP_STACK)
86 address = ::mmap(
nullptr, size, PROT_READ | PROT_WRITE, flags, -1, 0);
87 if (address == MAP_FAILED) {
98 PCHECK(::munmap(address, size) == 0);
105 return address == MAP_FAILED
107 : (
static_cast<char*
>(address) + size);
112 void* address = MAP_FAILED;
116 namespace signal_safe {
122 const lambda::function<
int()>& func)
131 const lambda::function<
int()>& func,
164 if (pid < 0 || !(flags & CLONE_VM)) {
178 static const long ticks = sysconf(_SC_CLK_TCK);
180 return Error(
"Failed to get sysconf(_SC_CLK_TCK)");
210 return Process(status.
get().
pid,
234 if (sysinfo(&info) != 0) {
238 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 23)
239 memory.total =
Bytes(info.totalram * info.mem_unit);
240 memory.free =
Bytes(info.freeram * info.mem_unit);
241 memory.totalSwap =
Bytes(info.totalswap * info.mem_unit);
242 memory.freeSwap =
Bytes(info.freeswap * info.mem_unit);
244 memory.total =
Bytes(info.totalram);
245 memory.free =
Bytes(info.freeram);
246 memory.totalSwap =
Bytes(info.totalswap);
247 memory.freeSwap =
Bytes(info.freeswap);
255 #endif // __STOUT_OS_LINUX_HPP__
const pid_t pgrp
Definition: proc.hpp:130
bool isNone() const
Definition: result.hpp:112
Definition: errorbase.hpp:35
Try< pid_t > clone(pid_t target, int nstypes, const lambda::function< int()> &f, int flags)
Performs an os::clone after entering a set of namespaces for the specified target process...
void deallocate()
Definition: linux.hpp:96
char * start() const
Definition: linux.hpp:103
static Result< T > error(const std::string &message)
Definition: result.hpp:53
size_t pagesize()
Definition: pagesize.hpp:24
Result< ProcessStatus > status(pid_t pid)
Definition: proc.hpp:166
const pid_t ppid
Definition: proc.hpp:129
static Try< Duration > create(double seconds)
Definition: duration.hpp:415
Definition: errorbase.hpp:49
Definition: result.hpp:40
const long rss
Definition: proc.hpp:149
DWORD pid_t
Definition: windows.hpp:187
const unsigned long utime
Definition: proc.hpp:139
Try< Nothing > utime(const std::string &path)
Definition: utime.hpp:32
Try< std::set< pid_t > > pids()
Definition: proc.hpp:294
static Option< T > none()
Definition: option.hpp:31
bool isSome() const
Definition: try.hpp:70
pid_t clone(const lambda::function< int()> &func, int flags)
Definition: linux.hpp:130
const pid_t session
Definition: proc.hpp:131
const T & get() const
Definition: result.hpp:115
const char state
Definition: proc.hpp:128
bool allocate()
Definition: linux.hpp:78
static constexpr size_t DEFAULT_SIZE
Definition: linux.hpp:58
Result< std::string > cmdline(const Option< pid_t > &pid=None())
Definition: proc.hpp:256
const pid_t pid
Definition: proc.hpp:126
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
#define flags
Definition: decoder.hpp:18
const std::string comm
Definition: proc.hpp:127
pid_t clone(const Stack &stack, int flags, const lambda::function< int()> &func)
Definition: linux.hpp:119
static Try< Stack > create(size_t size)
Definition: linux.hpp:62
const unsigned long stime
Definition: proc.hpp:140
bool isSome() const
Definition: result.hpp:111
bool isError() const
Definition: result.hpp:113
Try< Memory > memory()
Definition: freebsd.hpp:78
Stack(size_t size_)
Definition: linux.hpp:73
Try< std::set< pid_t > > pids()
Definition: freebsd.hpp:62
const T & get() const
Definition: try.hpp:73
int childMain(const std::string &path, char **argv, char **envp, const InputFileDescriptors &stdinfds, const OutputFileDescriptors &stdoutfds, const OutputFileDescriptors &stderrfds, bool blocking, int pipes[2], const std::vector< Subprocess::ChildHook > &child_hooks)
Definition: subprocess_posix.hpp:106