I'm not as good as Andrew or Aaron. But let me give it a shot.
solution 1:
keep time variable when you begin traversing the file
time_t old_counter;
While you inside the directory constantly keep getting
current time and subtract from the old_counter when you
began traversing the directory. use off course the
function difftime();
solution 2:
Set an alarm signal.
so
signal(SIGALM,timed_out);
#define TIMEOUT 60
alarm(TIMEOUT);
if your program get the signal
do the following action:
a) Set A flag to 1
b) reset the Alarm signal.
signal(SIGALRM,timed_out);
alarm(TIMEOUT);
while you are traversing your directory check for the value
of the flag. if it's one stop traversing and exit
loop. Else keep digging into the directory.
I hope that helps.
Hany E. Morcos (Your UNIX BUDDY)
: Hi,
: I'm searching for a possibility to read a directory with timeout. This is
: urgently necessary in AFS (it's a world wide network filesystem) because
: it takes a too long time to read all directory entries for example from
: /afs/ .
: I'm sure this is possible using an undocumented feature of some Unix
: derivates: Use select on the dd_fd component of the DIR structure.
: Since this is not for a "quick and dirty program" I'm not pleased about
: such a solution.
: Matthias Mueller-Reineke