linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "saravanaraj v" <saravanaraj.v@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Trouble reading a character device.
Date: Tue, 16 Dec 2008 12:41:38 +0530	[thread overview]
Message-ID: <2e0180190812152311l5d01e9aek6728832d5babbb14@mail.gmail.com> (raw)
In-Reply-To: <2e0180190812152308j64b827a2r21da6ff56e139f7e@mail.gmail.com>

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

       reply	other threads:[~2008-12-16  7:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <2e0180190812152308j64b827a2r21da6ff56e139f7e@mail.gmail.com>
2008-12-16  7:11 ` saravanaraj v [this message]
2008-12-16 14:51   ` Trouble reading a character device Glynn Clements
2008-12-18 12:17     ` saravanaraj v

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e0180190812152311l5d01e9aek6728832d5babbb14@mail.gmail.com \
    --to=saravanaraj.v@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).