kcmp — compare two processes to determine if they share a kernel resource
|unsigned long idx1,|
|unsigned long idx2
|There is no glibc wrapper for this system call; see NOTES.|
kcmp() system call can
be used to check whether the two processes identified by
pid2 share a kernel resource
such as virtual memory, file descriptors, and so on.
Permission to employ
is governed by ptrace access mode
PTRACE_MODE_READ_REALCREDS checks against
pid2; see ptrace(2).
specifies which resource is to be compared in the two
processes. It has one of the following values:
Check whether a file descriptor
idx1 in the process
pid1 refers to
the same open file description (see open(2)) as file
in the process
Check whether the process share the same set of open
file descriptors. The arguments
idx2 are ignored.
Check whether the processes share the same
filesystem information (i.e., file mode creation mask,
working directory, and filesystem root). The arguments
Check whether the processes share I/O context. The
Check whether the processes share the same table of
signal dispositions. The arguments
idx2 are ignored.
Check whether the processes share the same list of
System V semaphore undo operations. The arguments
Check whether the processes share the same address
space. The arguments
idx2 are ignored.
kcmp() is not
protected against false positives which may occur if the
processes are currently running. One should stop the
processes by sending
(see signal(7)) prior to
inspection with this system call to obtain meaningful
The return value of a successful call to
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.
v2 are the
addresses of appropriate resources, then the return value is
one of the following:
v1is equal to
v2; in other words, the two processes share the resource.
v1is less than
v1is greater than
v1is not equal to
v2, but ordering information is unavailable.
On error, −1 is returned, and
errno is set appropriately.
kcmp() was designed to
return values suitable for sorting. This is particularly
handy if one needs to compare a large number of file
fd2 is not an open file
Insufficient permission to inspect process
CAP_SYS_PTRACE capability is required
to inspect processes that you do not own. Other ptrace
limitations may also apply, such as
CONFIG_SECURITY_YAMA, which, when
kcmp() to child
processes; see ptrace(2).
Glibc does not provide a wrapper for this system call; call it using syscall(2).
This system call is available only if the kernel was
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
proc(5) filesystem; this
was deemed to be unsuitable for security reasons.
See clone(2) for some background information on the shared resources referred to on this page.
This page is part of release 4.07 of the Linux
man-pages project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
Copyright (C) 2012, Cyrill Gorcunov <gorcunovopenvz.org>
and Copyright (C) 2012, Michael Kerrisk <mtk.manpagesgmail.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
Formatted or processed versions of this manual, if unaccompanied by
the source, must acknowledge the copyright and authors of this work.
Kernel commit d97b46a64674a267bc41c9e16132ee2a98c3347d