OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[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-01-27 "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 file system information
78 (i.e., file mode creation mask, working directory, and file system 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 have place if tasks are
121 running.
122 Which means one should stop tasks being inspected with this syscall to obtain
123 meaningful results.
124 .SH RETURN VALUE
125 The return value of a successful call to
126 .BR kcmp ()
127 is simply the result of arithmetic comparison
128 of kernel pointers (when the kernel compares resources, it uses their
129 memory addresses).
130
131 The easiest way to explain is to consider an example.
132 Suppose that
133 .I v1
134 and
135 .I v2
136 are the addresses of appropriate resources, then the return value
137 is one of the following:
138 .RS 4
139 .IP 0 4
140 .I v1
141 is equal to
142 .IR v2 ;
143 in other words, the two processes share the resource.
144 .IP 1
145 .I v1
146 is less than
147 .IR v2 .
148 .IP 2
149 .I v1
150 is greater than
151 .IR v2 .
152 .IP 3
153 .I v1
154 is not equal to
155 .IR v2 ,
156 but ordering information is unavailable.
157 .RE
158 .PP
159 On error, \-1 is returned, and
160 .I errno
161 is set appropriately.
162
163 .B kcmp ()
164 was designed to return values suitable for sorting.
165 This is particularly handy if one needs to compare
166 a large number of file descriptors.
167 .SH ERRORS
168 .TP
169 .B EBADF
170 .I type
171 is
172 .B KCMP_FILE
173 and
174 .I fd1
175 or
176 .I fd2
177 is not an open file descriptor.
178 .TP
179 .B EINVAL
180 .I type
181 is invalid.
182 .TP
183 .B EPERM
184 Insufficient permission to inspect process resources.
185 The
186 .B CAP_SYS_PTRACE
187 capability is required to inspect processes that you do not own.
188 .TP
189 .B ESRCH
190 Process
191 .I pid1
192 or
193 .I pid2
194 does not exist.
195 .SH VERSIONS
196 The
197 .BR kcmp ()
198 system call first appeared in Linux 3.5.
199 .SH CONFORMING TO
200 .BR kcmp ()
201 is Linux specific and should not be used in programs intended to be portable.
202 .SH NOTES
203 Glibc does not provide a wrapper for this system call; call it using
204 .BR syscall (2).
205
206 This system call is available only if the kernel was configured with
207 .BR CONFIG_CHECKPOINT_RESTORE .
208 The main use of the system call is for the
209 checkpoint/restore in user space (CRIU) feature.
210 The alternative to this system call would have been to expose suitable
211 process information via the
212 .BR proc (5)
213 file system; this was deemed to be unsuitable for security reasons.
214
215 See
216 .BR clone (2)
217 for some background information on the shared resources
218 referred to on this page.
219 .SH SEE ALSO
220 .BR clone (2),
221 .BR unshare (2)