Big thanks, Salem.
However, I must admit, I lied a bit... I said I need linux command, because I'm compiling under MinGW, and I hoped the answer would be proper also for this. Unfortunately it seems that select() is one of POSIX functions, which MinGW doesn't support (damn, damn, damn...).
So I need to apologize and re-ask: could you help me find select() equivalent which would work under MinGW?
<edit>
I found something... I think.
It is a Winsock2.h select() function, which is similar to the Unix one.
(need to add -lws2_32 switch to make it link under MinGW)
The code I've written has one serious bug: the program doesn't go to sleep. I don't know if it is because I passed the descriptor/time in the wrong way, but it keeps looping just as if the select function didn't work.
Could you help me with that?
Code:
#include <iostream>
#include <Winsock2.h>
using namespace std;
int main(){
/*
this, I believe is creating a fd_set structure with one element pointing at Standard Input
std::cin should have 0 as his descriptor
*/
fd_set set = {1, {0}};//
/*
I'm not sure if both values should be equal or not, but it is a positive number
*/
timeval time = {5000, 5000000};
while (1){
cout<<"I start looping!!"<<endl;
int i = select (0, &set, NULL, NULL, &time); //Now the process *should* go to sleep for 5 seconds or more.
if (i == 0) cout <<"It's timeout!"<<endl; //if i!=, it means that the input woke the process, not timeout
}
}