12 #include <linux/unistd.h>
13 #include <linux/kcmp.h>
15 #include <sys/syscall.h>
16 #include <sys/types.h>
20 static long sys_kcmp(int pid1
, int pid2
, int type
, int fd1
, int fd2
)
22 return syscall(__NR_kcmp
, pid1
, pid2
, type
, fd1
, fd2
);
25 int main(int argc
, char **argv
)
27 const char kpath
[] = "kcmp-test-file";
32 fd1
= open(kpath
, O_RDWR
| O_CREAT
| O_TRUNC
, 0644);
36 perror("Can't create file");
42 perror("fork failed");
50 fd2
= open(kpath
, O_RDWR
, 0644);
52 perror("Can't open file");
56 /* An example of output and arguments */
57 printf("pid1: %6d pid2: %6d FD: %2ld FILES: %2ld VM: %2ld "
58 "FS: %2ld SIGHAND: %2ld IO: %2ld SYSVSEM: %2ld "
61 sys_kcmp(pid1
, pid2
, KCMP_FILE
, fd1
, fd2
),
62 sys_kcmp(pid1
, pid2
, KCMP_FILES
, 0, 0),
63 sys_kcmp(pid1
, pid2
, KCMP_VM
, 0, 0),
64 sys_kcmp(pid1
, pid2
, KCMP_FS
, 0, 0),
65 sys_kcmp(pid1
, pid2
, KCMP_SIGHAND
, 0, 0),
66 sys_kcmp(pid1
, pid2
, KCMP_IO
, 0, 0),
67 sys_kcmp(pid1
, pid2
, KCMP_SYSVSEM
, 0, 0),
69 /* This one should fail */
70 sys_kcmp(pid1
, pid2
, KCMP_TYPES
+ 1, 0, 0));
72 /* This one should return same fd */
73 ret
= sys_kcmp(pid1
, pid2
, KCMP_FILE
, fd1
, fd1
);
75 printf("FAIL: 0 expected but %d returned (%s)\n",
76 ret
, strerror(errno
));
79 printf("PASS: 0 returned as expected\n");
81 /* Compare with self */
82 ret
= sys_kcmp(pid1
, pid1
, KCMP_VM
, 0, 0);
84 printf("FAIL: 0 expected but %li returned (%s)\n",
85 ret
, strerror(errno
));
88 printf("PASS: 0 returned as expected\n");
93 waitpid(pid2
, &status
, P_ALL
);