1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
///@file

#include <optional>
#include <sys/resource.h>

#include "lix/libutil/types.hh"

namespace nix {

/**
 * If cgroups are active, attempt to calculate the number of CPUs available.
 * If cgroups are unavailable or if cpu.max is set to "max", return 0.
 */
unsigned int getMaxCPU();

/**
 * Increase the stack size rlimit if it is currently smaller than `stackSize`.
 */
void ensureStackSizeAtLeast(rlim_t stackSize);

/**
 * Restore the original inherited Unix process context (such as signal
 * masks, stack size). This should generally be called after fork for a process
 * intending to simply execve.
 *
 * See startSignalHandlerThread(), saveSignalMask().
 */
void restoreProcessContext();

/**
 * @return the path of the current executable.
 */
std::optional<Path> getSelfExe();

}