hi folks,
i read some bytes from a terminal device file and then i print them in stdout.The problem is that when i start reading /dev/pts4 file the console that corresponds to that file lags and typing is a bit hard.i think that something is wrong with my code but i cannot figure out what is going wrong.
check my code
Code:
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char **argv)
{
char buf[5];
int c;
int i=0;
size_t fd =open("/dev/pts/4",O_RDONLY,O_NONBLOCK);
memset(buf,0,sizeof(buf));
while(1)
{
ssize_t c =read(fd,buf,sizeof(buf));
if (c==-1)
{
printf("error");
return -1;
}
printf("chars:%s\n",buf);
}
return 0;
}
thanks in advance!!