1KCMP(2) Linux Programmer's Manual KCMP(2)
2
3
4
6 kcmp - compare two processes to determine if they share a kernel
7 resource
8
10 #include <linux/kcmp.h>
11
12 int kcmp(pid_t pid1, pid_t pid2, int type,
13 unsigned long idx1, unsigned long idx2);
14
15 Note: There is no glibc wrapper for this system call; see NOTES.
16
18 The kcmp() system call can be used to check whether the two processes
19 identified by pid1 and pid2 share a kernel resource such as virtual
20 memory, file descriptors, and so on.
21
22 The type argument specifies which resource is to be compared in the two
23 processes. It has one of the following values:
24
25 KCMP_FILE
26 Check whether a file descriptor idx1 in the process pid1 refers
27 to the same open file description (see open(2)) as file descrip‐
28 tor idx2 in the process pid2.
29
30 KCMP_FILES
31 Check whether the process share the same set of open file
32 descriptors. The arguments idx1 and idx2 are ignored.
33
34 KCMP_FS
35 Check whether the processes share the same file system informa‐
36 tion (i.e., file mode creation mask, working directory, and file
37 system root). The arguments idx1 and idx2 are ignored.
38
39 KCMP_IO
40 Check whether the processes share I/O context. The arguments
41 idx1 and idx2 are ignored.
42
43 KCMP_SIGHAND
44 Check whether the processes share the same table of signal dis‐
45 positions. The arguments idx1 and idx2 are ignored.
46
47 KCMP_SYSVSEM
48 Check whether the processes share the same list of System V sem‐
49 aphore undo operations. The arguments idx1 and idx2 are
50 ignored.
51
52 KCMP_VM
53 Check whether the processes share the same address space. The
54 arguments idx1 and idx2 are ignored.
55
56 Note the kcmp() is not protected against false positives which may have
57 place if tasks are running. Which means one should stop tasks being
58 inspected with this syscall to obtain meaningful results.
59
61 The return value of a successful call to kcmp() is simply the result of
62 arithmetic comparison of kernel pointers (when the kernel compares
63 resources, it uses their memory addresses).
64
65 The easiest way to explain is to consider an example. Suppose that v1
66 and v2 are the addresses of appropriate resources, then the return
67 value is one of the following:
68
69 0 v1 is equal to v2; in other words, the two processes share the
70 resource.
71
72 1 v1 is less than v2.
73
74 2 v1 is greater than v2.
75
76 3 v1 is not equal to v2, but ordering information is unavailable.
77
78 On error, -1 is returned, and errno is set appropriately.
79
80 kcmp () was designed to return values suitable for sorting. This is
81 particularly handy if one needs to compare a large number of file
82 descriptors.
83
85 EBADF type is KCMP_FILE and fd1 or fd2 is not an open file descriptor.
86
87 EINVAL type is invalid.
88
89 EPERM Insufficient permission to inspect process resources. The
90 CAP_SYS_PTRACE capability is required to inspect processes that
91 you do not own.
92
93 ESRCH Process pid1 or pid2 does not exist.
94
96 The kcmp() system call first appeared in Linux 3.5.
97
99 kcmp() is Linux specific and should not be used in programs intended to
100 be portable.
101
103 Glibc does not provide a wrapper for this system call; call it using
104 syscall(2).
105
106 This system call is available only if the kernel was configured with
107 CONFIG_CHECKPOINT_RESTORE. The main use of the system call is for the
108 checkpoint/restore in user space (CRIU) feature. The alternative to
109 this system call would have been to expose suitable process information
110 via the proc(5) file system; this was deemed to be unsuitable for secu‐
111 rity reasons.
112
113 See clone(2) for some background information on the shared resources
114 referred to on this page.
115
117 clone(2), unshare(2)
118
120 This page is part of release 3.53 of the Linux man-pages project. A
121 description of the project, and information about reporting bugs, can
122 be found at http://www.kernel.org/doc/man-pages/.
123
124
125
126Linux 2013-01-27 KCMP(2)