Trouble reading a character device.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
   I am facing few issues in reading from a character device.
   I have created few character devices using 'mknod' and I am writing
continuously to those devices using 'printk'. After some time I start
another process to read from the device. The open/read is done using
normal sys calls for file open/reading. I have pasted the code for
your ref. When I run this program the read happens for some time and
then there is no progress. I am suspecting that  everything written to
the device before this program was started is read. The flags I tried
for opening the file were RD, RDWR with/without NONBLOCK. The output
was same in all the cases. I tried "cu -l /dev/virt_uart8". It was
able to read continuosuly without any problem. Can someone tell where
the problem is ?


int main(){

int fd,counter=0;
fd = open("/dev/virt_uart8",O_RDONLY|O_NONBLOCK);
if(fd<0) printf("\nError in opeining file");
while(1){

                                        int nread = 0;
                                        nread =
read(fd,buffer,MAX_BUFFER_SIZE-1);
                                        if(nread>0) {
                                                buffer[nread]='\0';
                                                printf("%s",buffer);
                                        }

}
}



Thanks,
Saravanaraj
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux