GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
KCMP(2) FreeBSD System Calls Manual KCMP(2)

kcmpcompare two kernel objects

Standard C Library (libc, -lc)

#include <unistd.h>

int
kcmp(pid_t pid1, pid_t pid2, int type, uintptr_t idx1, uintptr_t idx2);

The kcmp system call allows the caller to determine whether the two processes with PIDs pid1 and pid2 reference the same kernel object. The type parameter specifies the type of object, and idx1 and idx2 are identifiers which refer to some object in the context of process pid1 and pid2, respectively.

The following values for type may be specified:

Compare two file descriptions referred to by file descriptors idx1 and idx2. They may be equivalent if, for example, one of the descriptors was created by applying dup(2) to the other descriptor.
Perform a “deep comparison” of the file descriptions referred to by file descriptors idx1 and idx2. This tests whether the underlying object referred to by the file descriptions is the same. For example, if the same filesystem path is opened twice, the kernel will create two separate file descriptions to back the two file descriptors, but they will refer to the same underlying object, a vnode(9). When compared using the KCMP_FILE type, these descriptors will be different, but using the KCMP_FILEOBJ type, they will be equal (assuming that the path was not unlinked in between the two opens).
Determine whether the two processes share the same file descriptor table. This will be the case if one of the processes was created by rfork(2) without specifying the RFFDG flag. The idx1 and idx2 parameters are ignored.
Determine whether the two processes share the same signal handler table. This will be the case if one of the processes was created using the RFSIGSHARE flag to rfork(2). The idx1 and idx2 parameters are ignored.
Determine whether the two processes share a virtual memory address space. This may be the case if one of the processes created the other using vfork(2) or rfork(2) with the RFMEM flag. The idx1 and idx2 parameters are ignored.
The caller of kcmp must have permission to debug both processes, otherwise the system call will fail.

If idx1 and idx2 refer to the same object, kcmp returns 0. If the object referred to by pid1 and idx1 is less or greater than the object referred to by pid2 and idx2, kcmp returns the values 1 and 2, respectively. The order is defined internally by the kernel and is stable until the system reboots. If the two objects cannot be compared for some reason, kcmp returns 3. For example, if type is KCMP_FILEOBJ and idx1 and idx2 are different descriptor types, e.g., a socket and a file, then kcmp will return 3.

If an error occurs, the value -1 is returned and the global variable errno is set to indicate the error.

kcmp may fail with the following errors:

[]
was specified and idx1 refers to a file descriptor which does not implement a comparison operator.
[]
The value of type is invalid.
[]
One of the file descriptors referred to by idx1 or idx2 is not valid.
[]
One of the processes referred to by pid1 or pid2 does not exist or is not visible (e.g., due to jail restrictions).
[]
The caller does not have permission to access one of the processes referred to by pid1 or pid2.

dup(2), fcntl(2), fork(2), rfork(2), vfork(2)

The kcmp system call originated in Linux. This implementation aims to be source-compatible with the Linux implementation. FreeBSD implements only a subset of the possible values for type supported in Linux. More values may be added in the future. The KCMP_FILEOBJ type is a FreeBSD extension.

The kcmp function was introduced in FreeBSD 14.1.

January 23, 2024 FreeBSD 14.3-RELEASE

Search for    or go to Top of page |  Section 2 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.