3cab65253a31e9c5bfafba0e7e68a3ab3eb4f816
[iec.git] / src / type3_AndroidCloud / anbox-master / external / process-cpp-minimal / include / core / posix / linux / proc / process / oom_adj.h
1 /*
2  * Copyright © 2012-2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 #ifndef CORE_POSIX_LINUX_PROC_PROCESS_OOM_ADJ_H_
19 #define CORE_POSIX_LINUX_PROC_PROCESS_OOM_ADJ_H_
20
21 #include <core/posix/visibility.h>
22
23 namespace core
24 {
25 namespace posix
26 {
27 class Process;
28 namespace linux
29 {
30 namespace proc
31 {
32 namespace process
33 {
34 /**
35  * This file can be used to adjust the score used to select which process
36  * should be killed in an out-of-memory (OOM) situation. The kernel uses this
37  * value for a bit-shift operation of the process's oom_score value: valid
38  * values are in the range -16 to +15, plus the special value -17, which disables
39  * OOM-killing altogether for this process. A positive score increases the
40  * likelihood of this process being killed by the OOM-killer; a negative score
41  * decreases the likelihood.
42  *
43  * The default value for this file is 0; a new process inherits its parent's
44  * oom_adj setting. A process must be privileged (CAP_SYS_RESOURCE) to update
45  * this file.
46  *
47  * Since Linux 2.6.36, use of this file is deprecated in favor of
48  * /proc/[pid]/oom_score_adj.
49  */
50 struct CORE_POSIX_DLL_PUBLIC OomAdj
51 {
52     /**
53      * @brief Returns the value that makes a process "invisible" to the oom killer.
54      * @return Returns the value that makes a process "invisible" to the oom killer.
55      */
56     static int disable_value();
57
58     /**
59      * @brief Returns the minimum valid value.
60      * @return The minimum valid value that the OomAdj can be set to.
61      */
62     static int min_value();
63
64     /**
65      * @brief Returns the maximum valid value.
66      * @return The maximum valid value that the OomAdj can be set to.
67      */
68     static int max_value();
69
70     /**
71      * @brief is_valid checks whether the contained value is within the predefined bounds.
72      * @return true iff min_value() <= value <= max_value().
73      */
74     inline bool is_valid() const
75     {
76         return (disable_value() <= value) && (value <= max_value());
77     }
78
79     /**
80      * @brief Current value.
81      */
82     int value;
83 };
84
85 /**
86  * \brief Read the OomAdj value for a process instance.
87  * \throws std::runtime_error in case of errors.
88  * \param [in] process The process to read the score for.
89  * \param [out] adj The destination to store the value in.
90  */
91 CORE_POSIX_DLL_PUBLIC const posix::Process& operator>>(const posix::Process& process, OomAdj& adj);
92
93 /**
94  * \brief Write the OomAdj value for a process instance.
95  * \throw std::runtime_error in case of errors and std::logic_error if score_adj.is_valid() returns false.
96  * \param [in] process The process to write the score for.
97  * \param [in] adj The new value to store.
98  */
99 CORE_POSIX_DLL_PUBLIC const posix::Process& operator<<(const posix::Process& process,
100                                  const OomAdj& adj);
101 }
102 }
103 }
104 }
105 }
106 #endif // CORE_POSIX_LINUX_PROC_PROCESS_OOM_ADJ_H_