can files be treated as streams in SYSV??
Too hot to handle
kender at eleazar.dartmouth.edu
Wed Aug 16 05:36:24 AEST 1989
I have a application that needs to follow the progress of a couple of files,
I'd like to use poll for this (shaddup you tail -f ers....I've my own reasons)
the code follows that has given me a bitch...the problem is that poll says that
there is always data to read even at eof...so I have this nagging feeling that
I cannot do this with a file...blah...I have R the FM and no mention that I
could find about not being able to treat a file like a stream...
---------------------------- code follows -----------------------------
#include <stdio.h>
#include <stropts.h>
#include <poll.h>
#define WAIT_FOR_EVENT -1
main(){
FILE *wf0 = fopen("watch0", "a+");
FILE *wf1 = fopen("watch1", "a+");
struct pollfd fds[2];
int timeout = WAIT_FOR_EVENT;
unsigned long nfds = 2; /* two files to watch */
char buf[80];
unsigned int nbyte = 80;
int i;
int cnt;
int ccnt;
fds[0].fd = fileno(wf0);
fds[0].events = POLLIN;
fds[1].fd = fileno(wf1);
fds[1].events = POLLIN;
printf("%d %d\n", fds[0].fd, fds[1].fd);
for(;;){
if ((cnt = poll(fds, nfds, timeout)) > 0) {
printf("Event detected on %d fd(s)\n", cnt);
fflush(stdout);
for(i=0;i<nfds;i++){
if (fds[i].revents){
ccnt = read(fds[i].fd, buf, nbyte);
printf("fd = %d, count = %d, buf = %s\n", fds[i].fd, ccnt, buf);
fflush(stdout);
}
}
} else if cnt < 0 {
perror("poll");
exit(1);
}
}
}
********************************************************************************
Cathy Huse: HB 1326, Dartmouth College, Hanover, New Hampshire; 03755
InterNet: kender at eleazar.dartmouth.edu
"What does an actor want with a conscience anyway?" --Jiminy Cricket
More information about the Comp.unix.questions
mailing list