-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect.c
More file actions
27 lines (20 loc) · 674 Bytes
/
select.c
File metadata and controls
27 lines (20 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdlib.h>
#include <sys/select.h>
int main(int argc, char *argv[]) {
//create file descriptor sets to observe
fd_set all_fd, responded_fd;
FD_ZERO(&all_fd);
// Add file descriptor (stdin in this case)
FD_SET(0, &all_fd);
//select is destructive. Using second variable
responded_fd = all_fd;
// wait for change in a file
int sel_err = select(FD_SETSIZE, &responded_fd, NULL, NULL, NULL);
if (sel_err == -1) {
// selection error
}
for (int i = 0; i < FD_SETSIZE; i++)
if (FD_ISSET(i, &responded_fd))
//change in the file with the file descriptor i occured
return EXIT_SUCCESS;
}