Q:

Running a timeout function in the background

I have a function:
int waiting()
{
fd_set          input_set;
struct timeval  timeout;
int             ready_for_reading = 0;
int             read_bytes = 0;

FD_ZERO(&input_set );
FD_SET(0, &input_set);

timeout.tv_sec = WAIT;    // WAIT seconds
timeout.tv_usec = 0;    // 0 milliseconds

printf("^[[10;53H^[[1;34;44m   LOGIN TO BBS   ^[[0;37m", WAIT);
printf("^[[11;53H^[[34;46m   apply to bbs   ^[[0;37m", WAIT);
printf("^[[12;53H^[[34;46m    page sysop    ^[[0;37m", WAIT);
printf("^[[13;53H^[[34;46m   logout of bbs  ^[[0;37m", WAIT);
printf("\n", WAIT);

ready_for_reading = select(1, &input_set, NULL, NULL, &timeout);

if (ready_for_reading == -1) {
    return -1;
}
if (ready_for_reading) {

} else {
    exit(1);
}

return 0;
}

It times out, like it should, The problem is that it only works when the user doesn't input anything. I'd like it to work regardless of if the user inputs anything. Specifically, if the user uses the arrows to select one of the choices, but doesn't hit enter to actually select it. The entire point of this is, so people who call my BBS, if they telnet to it, and are at the menu, it will time out on them if they don't do anything. A problem i'm having, is some people call up my BBS, and login, but don't actually do anything. And it doesn't exit like it should. Locking up a node on the BBS. Also, I'd like to run this function in the background. Is that possible?

A:

Ok. I found a function that does exactly what I want it to do. alarm().
I set alarm(15) where I put the waiting function, and then add a alarm(0) where I want it to not time out.

