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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
* virprocess.h: interaction with processes
*
* Copyright (C) 2010-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include <sys/types.h>
#include "internal.h"
#include "virbitmap.h"
#include "virenum.h"
typedef enum {
VIR_PROC_POLICY_NONE = 0,
VIR_PROC_POLICY_BATCH,
VIR_PROC_POLICY_IDLE,
VIR_PROC_POLICY_FIFO,
VIR_PROC_POLICY_RR,
VIR_PROC_POLICY_LAST
} virProcessSchedPolicy;
VIR_ENUM_DECL(virProcessSchedPolicy);
char *
virProcessTranslateStatus(int status);
void
virProcessAbort(pid_t pid);
void virProcessExitWithStatus(int status) G_GNUC_NORETURN;
int
virProcessWait(pid_t pid, int *exitstatus, bool raw)
G_GNUC_WARN_UNUSED_RESULT;
int virProcessKill(pid_t pid, int sig);
int virProcessGroupKill(pid_t pid, int sig);
pid_t virProcessGroupGet(pid_t pid);
int virProcessKillPainfully(pid_t pid, bool force);
int virProcessKillPainfullyDelay(pid_t pid,
bool force,
unsigned int extradelay,
bool group);
int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet);
virBitmap *virProcessGetAffinity(pid_t pid);
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids);
int virProcessGetStartTime(pid_t pid,
unsigned long long *timestamp);
int virProcessGetNamespaces(pid_t pid,
size_t *nfdlist,
int **fdlist);
int virProcessSetNamespaces(size_t nfdlist,
int *fdlist);
int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes) G_NO_INLINE;
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
int virProcessGetMaxMemLock(pid_t pid, unsigned long long *bytes) G_NO_INLINE;
/* Callback to run code within the mount namespace tied to the given
* pid. This function must use only async-signal-safe functions, as
* it gets run after a fork of a multi-threaded process. The return
* value of this function is passed to _exit(), except that a
* negative value is treated as EXIT_CANCELED. */
typedef int (*virProcessNamespaceCallback)(pid_t pid, void *opaque);
int virProcessRunInMountNamespace(pid_t pid,
virProcessNamespaceCallback cb,
void *opaque);
/**
* virProcessForkCallback:
* @ppid: parent's pid
* @opaque: opaque data
*
* Callback to run in fork()-ed process.
*
* Returns: 0 on success,
* -1 on error (treated as EXIT_CANCELED)
*/
typedef int (*virProcessForkCallback)(pid_t ppid,
void *opaque);
int virProcessRunInFork(virProcessForkCallback cb,
void *opaque)
G_NO_INLINE;
int virProcessSetupPrivateMountNS(void);
int virProcessSetScheduler(pid_t pid,
virProcessSchedPolicy policy,
int priority);
GStrv virProcessGetStat(pid_t pid, pid_t tid);
/* These constants are modelled after proc(5) */
enum {
VIR_PROCESS_STAT_PID,
VIR_PROCESS_STAT_COMM,
VIR_PROCESS_STAT_STATE,
VIR_PROCESS_STAT_PPID,
VIR_PROCESS_STAT_PGRP,
VIR_PROCESS_STAT_SESSION,
VIR_PROCESS_STAT_TTY_NR,
VIR_PROCESS_STAT_TPGID,
VIR_PROCESS_STAT_FLAGS,
VIR_PROCESS_STAT_MINFLT,
VIR_PROCESS_STAT_CMINFLT,
VIR_PROCESS_STAT_MAJFLT,
VIR_PROCESS_STAT_CMAJFLT,
VIR_PROCESS_STAT_UTIME,
VIR_PROCESS_STAT_STIME,
VIR_PROCESS_STAT_CUTIME,
VIR_PROCESS_STAT_CSTIME,
VIR_PROCESS_STAT_PRIORITY,
VIR_PROCESS_STAT_NICE,
VIR_PROCESS_STAT_NUM_THREADS,
VIR_PROCESS_STAT_ITREALVALUE,
VIR_PROCESS_STAT_STARTTIME,
VIR_PROCESS_STAT_VSIZE,
VIR_PROCESS_STAT_RSS,
VIR_PROCESS_STAT_RSSLIM,
VIR_PROCESS_STAT_STARTCODE,
VIR_PROCESS_STAT_ENDCODE,
VIR_PROCESS_STAT_STARTSTACK,
VIR_PROCESS_STAT_KSTKESP,
VIR_PROCESS_STAT_KSTKEIP,
VIR_PROCESS_STAT_SIGNAL,
VIR_PROCESS_STAT_BLOCKED,
VIR_PROCESS_STAT_SIGIGNORE,
VIR_PROCESS_STAT_SIGCATCH,
VIR_PROCESS_STAT_WCHAN,
VIR_PROCESS_STAT_NSWAP,
VIR_PROCESS_STAT_CNSWAP,
VIR_PROCESS_STAT_EXIT_SIGNAL,
VIR_PROCESS_STAT_PROCESSOR,
VIR_PROCESS_STAT_RT_PRIORITY,
VIR_PROCESS_STAT_POLICY,
VIR_PROCESS_STAT_DELAYACCT_BLKIO_TICKS,
VIR_PROCESS_STAT_GUEST_TIME,
VIR_PROCESS_STAT_CGUEST_TIME,
VIR_PROCESS_STAT_START_DATA,
VIR_PROCESS_STAT_END_DATA,
VIR_PROCESS_STAT_START_BRK,
VIR_PROCESS_STAT_ARG_START,
VIR_PROCESS_STAT_ARG_END,
VIR_PROCESS_STAT_ENV_START,
VIR_PROCESS_STAT_ENV_END,
VIR_PROCESS_STAT_EXIT_CODE,
};
/*
* At the time of writing there are 52 values reported in /proc/.../stat, the
* line below checks that the last one has the right value, increase accordingly
* based on proc(5) whenever adding new fields.
*/
G_STATIC_ASSERT(VIR_PROCESS_STAT_EXIT_CODE == 51);
typedef enum {
VIR_PROCESS_NAMESPACE_MNT = (1 << 1),
VIR_PROCESS_NAMESPACE_IPC = (1 << 2),
VIR_PROCESS_NAMESPACE_NET = (1 << 3),
VIR_PROCESS_NAMESPACE_PID = (1 << 4),
VIR_PROCESS_NAMESPACE_USER = (1 << 5),
VIR_PROCESS_NAMESPACE_UTS = (1 << 6),
} virProcessNamespaceFlags;
int virProcessNamespaceAvailable(unsigned int ns);
int virProcessGetStatInfo(unsigned long long *cpuTime,
unsigned long long *userTime,
unsigned long long *sysTime,
int *lastCpu,
long *vm_rss,
pid_t pid,
pid_t tid);
int virProcessGetSchedInfo(unsigned long long *cpuWait,
pid_t pid,
pid_t tid);
int virProcessSchedCoreAvailable(void);
int virProcessSchedCoreCreate(void);
int virProcessSchedCoreShareFrom(pid_t pid);
int virProcessSchedCoreShareTo(pid_t pid);
|