mirror of
https://github.com/Hizenberg469/Driver-tutorial.git
synced 2026-04-19 16:32:23 +03:00
done till multi2.c
This commit is contained in:
22
select_poll/multi1.c
Normal file
22
select_poll/multi1.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int main(){
|
||||
int fd1, fd2;
|
||||
char buf[10];
|
||||
int n;
|
||||
fd1 = open("./pone", O_RDWR);
|
||||
fd2 = open("./ptwo", O_RDWR);
|
||||
|
||||
printf(" Trying to read from pone \n");
|
||||
n = read( fd1, buf, 10);
|
||||
|
||||
printf(" read data = %s from pone \n", buf);
|
||||
printf(" Trying to read from ptwo\n");
|
||||
n = read( fd2, buf, 10);
|
||||
|
||||
printf(" read data = %s from ptwo \n", buf);
|
||||
return 0;
|
||||
}
|
||||
BIN
select_poll/multi2
Executable file
BIN
select_poll/multi2
Executable file
Binary file not shown.
46
select_poll/multi2.c
Normal file
46
select_poll/multi2.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(){
|
||||
|
||||
int fd1, fd2;
|
||||
fd_set read_set, write_set;
|
||||
char buf[10];
|
||||
struct timeval timeout;
|
||||
int n;
|
||||
|
||||
timeout.tv_sec = 10;
|
||||
fd1 = open("./pone", O_RDWR);
|
||||
fd2 = open("./ptwo", O_RDWR);
|
||||
|
||||
FD_ZERO(&read_set);
|
||||
FD_SET(fd1, &read_set);
|
||||
FD_SET(fd2, &read_set);
|
||||
|
||||
n = select(FD_SETSIZE, &read_set, NULL, NULL, &timeout);
|
||||
if( n < 0 ){
|
||||
perror("select ");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// test whether fd1 is ready or not
|
||||
if( FD_ISSET(fd1, &read_set) ){
|
||||
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( FD_ISSET(fd2, &read_set) ){
|
||||
printf(" reading from fd2 (ptwo)\n");
|
||||
n = read(fd2, buf, 10);
|
||||
printf(" read data = %s from ptwo \n", buf);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user