OSDN Git Service

Update README
[linuxjm/LDP_man-pages.git] / original / man2 / kcmp.2
1 .\" Copyright (C) 2012, Cyrill Gorcunov <gorcunov@openvz.org>
2 .\" and Copyright (C) 2012, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of
10 .\" this manual under the conditions for verbatim copying, provided that
11 .\" the entire resulting derived work is distributed under the terms of
12 .\" a permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume
16 .\" no responsibility for errors or omissions, or for damages resulting
17 .\" from the use of the information contained herein.  The author(s) may
18 .\" not have taken the same level of care in the production of this
19 .\" manual, which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Kernel commit d97b46a64674a267bc41c9e16132ee2a98c3347d
27 .\"
28 .TH KCMP 2 2013-12-08 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 kcmp \- compare two processes to determine if they share a kernel resource
31 .SH SYNOPSIS
32 .nf
33 .B #include <linux/kcmp.h>
34
35 .BI "int kcmp(pid_t " pid1 ", pid_t " pid2 ", int " type ,
36 .BI "         unsigned long " idx1 ", unsigned long "  idx2 );
37 .fi
38
39 .IR Note :
40 There is no glibc wrapper for this system call; see NOTES.
41 .SH DESCRIPTION
42 The
43 .BR kcmp ()
44 system call can be used to check whether the two processes identified by
45 .I pid1
46 and
47 .I pid2
48 share a kernel resource such as virtual memory, file descriptors,
49 and so on.
50
51 The
52 .I type
53 argument specifies which resource is to be compared in the two processes.
54 It has one of the following values:
55 .TP
56 .BR KCMP_FILE
57 Check whether a file descriptor
58 .I idx1
59 in the process
60 .I pid1
61 refers to the same open file description (see
62 .BR open (2))
63 as file descriptor
64 .I idx2
65 in the process
66 .IR pid2 .
67 .TP
68 .BR KCMP_FILES
69 Check whether the process share the same set of open file descriptors.
70 The arguments
71 .I idx1
72 and
73 .I idx2
74 are ignored.
75 .TP
76 .BR KCMP_FS
77 Check whether the processes share the same filesystem information
78 (i.e., file mode creation mask, working directory, and filesystem root).
79 The arguments
80 .I idx1
81 and
82 .I idx2
83 are ignored.
84 .TP
85 .BR KCMP_IO
86 Check whether the processes share I/O context.
87 The arguments
88 .I idx1
89 and
90 .I idx2
91 are ignored.
92 .TP
93 .BR KCMP_SIGHAND
94 Check whether the processes share the same table of signal dispositions.
95 The arguments
96 .I idx1
97 and
98 .I idx2
99 are ignored.
100 .TP
101 .BR KCMP_SYSVSEM
102 Check whether the processes share the same
103 list of System\ V semaphore undo operations.
104 The arguments
105 .I idx1
106 and
107 .I idx2
108 are ignored.
109 .TP
110 .BR KCMP_VM
111 Check whether the processes share the same address space.
112 The arguments
113 .I idx1
114 and
115 .I idx2
116 are ignored.
117 .PP
118 Note the
119 .BR kcmp ()
120 is not protected against false positives which may occur if tasks are
121 running.
122 One should stop tasks by sending
123 .BR SIGSTOP
124 (see
125 .BR signal (7))
126 prior to inspection with this system call to obtain meaningful results.
127 .SH RETURN VALUE
128 The return value of a successful call to
129 .BR kcmp ()
130 is simply the result of arithmetic comparison
131 of kernel pointers (when the kernel compares resources, it uses their
132 memory addresses).
133
134 The easiest way to explain is to consider an example.
135 Suppose that
136 .I v1
137 and
138 .I v2
139 are the addresses of appropriate resources, then the return value
140 is one of the following:
141 .RS 4
142 .IP 0 4
143 .I v1
144 is equal to
145 .IR v2 ;
146 in other words, the two processes share the resource.
147 .IP 1
148 .I v1
149 is less than
150 .IR v2 .
151 .IP 2
152 .I v1
153 is greater than
154 .IR v2 .
155 .IP 3
156 .I v1
157 is not equal to
158 .IR v2 ,
159 but ordering information is unavailable.
160 .RE
161 .PP
162 On error, \-1 is returned, and
163 .I errno
164 is set appropriately.
165
166 .BR kcmp ()
167 was designed to return values suitable for sorting.
168 This is particularly handy if one needs to compare
169 a large number of file descriptors.
170 .SH ERRORS
171 .TP
172 .B EBADF
173 .I type
174 is
175 .B KCMP_FILE
176 and
177 .I fd1
178 or
179 .I fd2
180 is not an open file descriptor.
181 .TP
182 .B EINVAL
183 .I type
184 is invalid.
185 .TP
186 .B EPERM
187 Insufficient permission to inspect process resources.
188 The
189 .B CAP_SYS_PTRACE
190 capability is required to inspect processes that you do not own.
191 .TP
192 .B ESRCH
193 Process
194 .I pid1
195 or
196 .I pid2
197 does not exist.
198 .SH VERSIONS
199 The
200 .BR kcmp ()
201 system call first appeared in Linux 3.5.
202 .SH CONFORMING TO
203 .BR kcmp ()
204 is Linux-specific and should not be used in programs intended to be portable.
205 .SH NOTES
206 Glibc does not provide a wrapper for this system call; call it using
207 .BR syscall (2).
208
209 This system call is available only if the kernel was configured with
210 .BR CONFIG_CHECKPOINT_RESTORE .
211 The main use of the system call is for the
212 checkpoint/restore in user space (CRIU) feature.
213 The alternative to this system call would have been to expose suitable
214 process information via the
215 .BR proc (5)
216 filesystem; this was deemed to be unsuitable for security reasons.
217
218 See
219 .BR clone (2)
220 for some background information on the shared resources
221 referred to on this page.
222 .SH SEE ALSO
223 .BR clone (2),
224 .BR unshare (2)
225 .SH COLOPHON
226 This page is part of release 3.79 of the Linux
227 .I man-pages
228 project.
229 A description of the project,
230 information about reporting bugs,
231 and the latest version of this page,
232 can be found at
233 \%http://www.kernel.org/doc/man\-pages/.