Select function in my case always returns zero, which is timeout and this is happening continuosly so my CPU usage also going upto 98 % for my process. I have also tried to set NULL instead of seting some timeout value , still it returns zero. I also used poll function replacing select. The same issue came with the poll also.
here is part of my code;
while(1)
{
value = 0;
selectTimeOut = 0;
memset(buf,0,SIZE);
FD_ZERO(&read_fds);
FD_SET(fd, &read_fds);
struct timeval tv;
tv.tv_sec = 10;
tv.tv_usec = 1000;
fdmax = fd;
//using select to reduce cpu utilization
selectret = select(fdmax + 1,&read_fds,NULL,NULL,&tv);
if (selectret == -1)
{
print_sync("/home/fes/syclogs.txt","Select fails");
exit(0);
}
else
{
print_sync("/home/fes/syclogs.txt","Error set is %s",strerror(errno));
if(!FD_ISSET(fd, &read_fds))
{
print_sync("/home/fes/syclogs.txt","Select Time Out");
selectTimeOut = 1;
}
}
if(selectTimeOut == 1)
continue;
noread = read(fd,buf,SIZE);
}