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)");
219 status->
state ==
'Z');
235 if (sysinfo(&info) != 0) {
239 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 23) 240 memory.
total =
Bytes(info.totalram * info.mem_unit);
241 memory.
free =
Bytes(info.freeram * info.mem_unit);
256 #endif // __STOUT_OS_LINUX_HPP__ const pid_t pgrp
Definition: proc.hpp:130
bool isNone() const
Definition: result.hpp:113
Definition: errorbase.hpp:36
void deallocate()
Definition: linux.hpp:96
char * start() const
Definition: linux.hpp:103
T & get()&
Definition: try.hpp:80
static Result< T > error(const std::string &message)
Definition: result.hpp:54
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:418
int childMain(const std::string &path, char **argv, char **envp, const InputFileDescriptors &stdinfds, const OutputFileDescriptors &stdoutfds, const OutputFileDescriptors &stderrfds, const std::vector< int_fd > &whitelist_fds, bool blocking, int pipes[2], const std::vector< Subprocess::ChildHook > &child_hooks)
Definition: subprocess.hpp:216
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
Bytes freeSwap
Definition: os.hpp:39
const long rss
Definition: proc.hpp:149
DWORD pid_t
Definition: windows.hpp:181
Definition: process.hpp:32
Bytes totalSwap
Definition: os.hpp:38
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:32
bool isSome() const
Definition: try.hpp:77
pid_t clone(const lambda::function< int()> &func, int flags)
Definition: linux.hpp:130
const pid_t session
Definition: proc.hpp:131
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
Bytes total
Definition: os.hpp:36
T & get()&
Definition: result.hpp:116
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:112
bool isError() const
Definition: result.hpp:114
Try< Memory > memory()
Definition: freebsd.hpp:78
Stack(size_t size_)
Definition: linux.hpp:73
Bytes free
Definition: os.hpp:37
Try< std::set< pid_t > > pids()
Definition: freebsd.hpp:62