几个例子,看懂poll和epoll
1. poll的例子 #include <stdio.h> #include <sys/eventfd.h> #include <poll.h> int main() { uint64_t value = 2; int event_fd = eventfd(0, EFD_NONBLOCK); struct pollfd pfd; int status = 0; uint64_t check_value = 0; printf("event_fd=%d\n", event_fd); write(event_fd, &value, sizeof(value)); write(event_fd, &value, sizeof(value)); write(event_fd, &value, sizeof(value)); read(event_fd, &check_value, sizeof(check_value)); printf("read, value=%ld\n", check_value); int ret = fork(); if (ret < 0) { printf("fork error\n"); } if (ret == 0) { pfd.fd = event_fd; pfd.events = POLLIN; printf("__FILE: %s, __LINE: