/* * Test for kernel threadness atomically with openat(). * * Return /proc/$PID/fd descriptor if process is kernel thread. * Return -1 if a process is userspace process.
*/ staticint kernel_thread_fd(unsignedint pid)
{ unsignedint flags = 0; char buf[4096]; int dir_fd, fd;
ssize_t rv;
staticvoid test_lookup(int fd)
{ char buf[64]; unsignedint u; int i;
for (i = INT_MIN; i < INT_MIN + 1024; i++) {
snprintf(buf, sizeof(buf), "%d", i);
test_lookup_fail(fd, buf);
} for (i = -1024; i < 1024; i++) {
snprintf(buf, sizeof(buf), "%d", i);
test_lookup_fail(fd, buf);
} for (u = INT_MAX - 1024; u < (unsignedint)INT_MAX + 1024; u++) {
snprintf(buf, sizeof(buf), "%u", u);
test_lookup_fail(fd, buf);
} for (u = UINT_MAX - 1024; u != 0; u++) {
snprintf(buf, sizeof(buf), "%u", u);
test_lookup_fail(fd, buf);
}
}
int main(void)
{ unsignedint pid; int fd;
/* * In theory this will loop indefinitely if kernel threads are exiled * from /proc. * * Start with kthreadd.
*/
pid = 2; while ((fd = kernel_thread_fd(pid)) == -1 && pid < 1024) {
pid++;
} /* EACCES if run as non-root. */ if (pid >= 1024) return 1;
test_readdir(fd);
test_lookup(fd);
return 0;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.