Interrupting blocked read
问题 My program goes through a loop like this: ... while(1){ read(sockfd,buf,sizeof(buf)); ... } The read function blocks when it is waiting for input, which happens to be from a socket. I want to handle SIGINT and basically tell it to stop the read function if it is reading and then call an arbitrary function. What is the best way to do this? 回答1: From read(2) : EINTR The call was interrupted by a signal before any data was read; see signal(7). If you amend your code to look more like: cont = 1;