Character driver finished

This commit is contained in:
2025-02-24 14:18:48 +00:00
parent 5500b9dc74
commit 3681dbfaac
12 changed files with 340 additions and 1 deletions

46
select_poll/poll1.c Normal file
View File

@@ -0,0 +1,46 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdlib.h>
int main(){
int fd1, fd2;
struct pollfd pollarray[10];
char buf[10];
int n;
fd1 = open("./pone", O_RDWR);
fd2 = open("./ptwo", O_RDWR);
pollarray[0].fd = fd1;
pollarray[1].fd = fd2;
pollarray[0].events = POLLIN;
pollarray[1].events = POLLIN;
n = poll(pollarray, 2, 10000);
if(n < 0){
perror("poll:");
exit(1);
}
//test whether fd1 is ready or not
if( (pollarray[0].revents & POLLIN)){
printf(" reading from fd1 (pone)\n");
n = read(fd1, buf, 10);
printf(" read data = %s from pone\n", buf);
}
//test whether fd2 is ready or not
if( (pollarray[1].revents & POLLIN)){
printf(" reading from fd2 (ptwo)\n");
n = read(fd2, buf, 10);
printf(" read data = %s from ptwo\n", buf);
}
// close(fd1);
// close(fd2);
return 0;
}