summaryrefslogtreecommitdiffstats
path: root/man2/kcmp.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/kcmp.2')
-rw-r--r--man2/kcmp.230
1 files changed, 15 insertions, 15 deletions
diff --git a/man2/kcmp.2 b/man2/kcmp.2
index 7c02b5c44..d1c24130c 100644
--- a/man2/kcmp.2
+++ b/man2/kcmp.2
@@ -323,7 +323,7 @@ An example run of the program is as follows:
$ \fB./a.out\fP
Parent PID is 1144
Parent opened file on FD 3
-
+\&
PID of child of fork() is 1145
Compare duplicate FDs from different processes:
kcmp(1145, 1144, KCMP_FILE, 3, 3) ==> same
@@ -349,14 +349,14 @@ Child duplicated FD 3 to create FD 5
#include <sys/syscall.h>
#include <sys/wait.h>
#include <unistd.h>
-
+\&
static int
kcmp(pid_t pid1, pid_t pid2, int type,
unsigned long idx1, unsigned long idx2)
{
return syscall(SYS_kcmp, pid1, pid2, type, idx1, idx2);
}
-
+\&
static void
test_kcmp(char *msg, pid_t pid1, pid_t pid2, int fd_a, int fd_b)
{
@@ -366,51 +366,51 @@ test_kcmp(char *msg, pid_t pid1, pid_t pid2, int fd_a, int fd_b)
(kcmp(pid1, pid2, KCMP_FILE, fd_a, fd_b) == 0) ?
"same" : "different");
}
-
+\&
int
main(void)
{
int fd1, fd2, fd3;
static const char pathname[] = "/tmp/kcmp.test";
-
+\&
fd1 = open(pathname, O_CREAT | O_RDWR, 0600);
if (fd1 == \-1)
err(EXIT_FAILURE, "open");
-
+\&
printf("Parent PID is %jd\en", (intmax_t) getpid());
printf("Parent opened file on FD %d\en\en", fd1);
-
+\&
switch (fork()) {
case \-1:
err(EXIT_FAILURE, "fork");
-
+\&
case 0:
printf("PID of child of fork() is %jd\en", (intmax_t) getpid());
-
+\&
test_kcmp("Compare duplicate FDs from different processes:",
getpid(), getppid(), fd1, fd1);
-
+\&
fd2 = open(pathname, O_CREAT | O_RDWR, 0600);
if (fd2 == \-1)
err(EXIT_FAILURE, "open");
printf("Child opened file on FD %d\en", fd2);
-
+\&
test_kcmp("Compare FDs from distinct open()s in same process:",
getpid(), getpid(), fd1, fd2);
-
+\&
fd3 = dup(fd1);
if (fd3 == \-1)
err(EXIT_FAILURE, "dup");
printf("Child duplicated FD %d to create FD %d\en", fd1, fd3);
-
+\&
test_kcmp("Compare duplicated FDs in same process:",
getpid(), getpid(), fd1, fd3);
break;
-
+\&
default:
wait(NULL);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE