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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
.\" Copyright (C) 2012, Cyrill Gorcunov <gorcunov@openvz.org>
.\" and Copyright (C) 2012, Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of
.\" this manual under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of
.\" a permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume.
.\" no responsibility for errors or omissions, or for damages resulting.
.\" from the use of the information contained herein. The author(s) may.
.\" not have taken the same level of care in the production of this.
.\" manual, which is licensed free of charge, as they might when working.
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.\" Kernel commit d97b46a64674a267bc41c9e16132ee2a98c3347d
.\"
.TH KCMP 2 2013-01-27 "Linux" "Linux Programmer's Manual"
.SH NAME
kcmp \- compare two processes to determine if they share a kernel resource
.SH SYNOPSIS
.nf
.B #include <linux/kcmp.h>
.BI "int kcmp(pid_t " pid1 ", pid_t " pid2 ", int " type ,
.BI " unsigned long " idx1 ", unsigned long " idx2 );
.fi
.IR Note :
There is no glibc wrapper for this system call; see NOTES.
.SH DESCRIPTION
The
.BR kcmp ()
system call can be used to check whether the two processes identified by
.I pid1
and
.I pid2
share a kernel resource such as virtual memory, file descriptors,
and so on.
The
.I type
argument specifies which resource is to be compared in the two processes.
It has one of the following values:
.TP
.BR KCMP_FILE
Check whether a file descriptor
.I idx1
in the process
.I pid1
refers to the same open file description (see
.BR open (2))
as file descriptor
.I idx2
in the process
.IR pid2 .
.TP
.BR KCMP_FILES
Check whether the process share the same set of open file descriptors.
The arguments
.I idx1
and
.I idx2
are ignored.
.TP
.BR KCMP_FS
Check whether the processes share the same file system information
(i.e., file mode creation mask, working directory, and file system root).
The arguments
.I idx1
and
.I idx2
are ignored.
.TP
.BR KCMP_IO
Check whether the processes share I/O context.
The arguments
.I idx1
and
.I idx2
are ignored.
.TP
.BR KCMP_SIGHAND
Check whether the processes share the same table of signal dispositions.
The arguments
.I idx1
and
.I idx2
are ignored.
.TP
.BR KCMP_SYSVSEM
Check whether the processes share the same
list of System V semaphore undo operations.
The arguments
.I idx1
and
.I idx2
are ignored.
.TP
.BR KCMP_VM
Check whether the processes share the same address space.
The arguments
.I idx1
and
.I idx2
are ignored.
.PP
Note the
.BR kcmp ()
is not protected against false positives which may have place if tasks are
running.
Which means one should stop tasks being inspected with this syscall to obtain
meaningful results.
.SH "RETURN VALUE"
The return value of a successful call to
.BR kcmp ()
is simply the result of arithmetic comparison
of kernel pointers (when the kernel compares resources, it uses their
memory addresses).
The easiest way to explain is to consider an example.
Suppose that
.I v1
and
.I v2
are the addresses of appropriate resources, then the return value
is one of the following:
.RS 4
.IP 0 4
.I v1
is equal to
.IR v2 ;
in other words, the two processes share the resource.
.IP 1
.I v1
is less than
.IR v2 .
.IP 2
.I v1
is greater than
.IR v2 .
.IP 3
.I v1
is not equal to
.IR v2 ,
but ordering information is unavailable.
.RE
.PP
On error, \-1 is returned, and
.I errno
is set appropriately.
.B kcmp ()
was designed to return values suitable for sorting.
This is particularly handy if one needs to compare
a large number of file descriptors.
.SH ERRORS
.TP
.B EBADF
.I type
is
.B KCMP_FILE
and
.I fd1
or
.I fd2
is not an open file descriptor.
.TP
.B EINVAL
.I type
is invalid.
.TP
.B EPERM
Insufficient permission to inspect process resources.
The
.B CAP_SYS_PTRACE
capability is required to inspect processes that you do not own.
.TP
.B ESRCH
Process
.I pid1
or
.I pid2
does not exist.
.SH VERSIONS
The
.BR kcmp ()
system call first appeared in Linux 3.5.
.SH "CONFORMING TO"
.BR kcmp ()
is Linux specific and should not be used in programs intended to be portable.
.SH NOTES
Glibc does not provide a wrapper for this system call; call it using
.BR syscall (2).
This system call is available only if the kernel was configured with
.BR CONFIG_CHECKPOINT_RESTORE .
The main use of the system call is for the
checkpoint/restore in user space (CRIU) feature.
The alternative to this system call would have been to expose suitable
process information via the
.BR proc (5)
file system; this was deemed to be unsuitable for security reasons.
See
.BR clone (2)
for some background information on the shared resources
referred to on this page.
.SH "SEE ALSO"
.BR clone (2),
.BR unshare (2)
|