timeout while reading a directory

timeout while reading a directory

Post by Matthias Mueller-Reinek » Thu, 23 Jul 1998 04:00:00



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

 
 
 

timeout while reading a directory

Post by Marcelo Meir » Thu, 23 Jul 1998 04:00:00


Use alarm() / sigaction()

  Marcelo


> 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

--

----------------
Marcelo L. Meira, Programmer

e-mail: marcelo.meira at waii dot com
Western Geophysical - (713) 689-2679

"UNIX _IS_ user friendly; it's just picky about who its friends are."

 
 
 

timeout while reading a directory

Post by Hany Morcos ( » Thu, 23 Jul 1998 04:00:00


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

 
 
 

1. Press Ctrl-D whiling inputting

I write a program:

#include <stdio.h>
main()
{
   char str[81];
   while(1)
   {
      gets(str);
      printf("You input: %s\n",str);
   }

My question is why it causes infinitely loop after I press Ctrl-D.
Is there any solution about this?  Thanks.

--
     +------------------------------------------------------------+
    / \   Trying to maintain a good friendship with all people   / \
   /   + - - - - - - - - - - - - - - - - - - - - - - - - - - - -/ - +


+------------------------------------------------------------+   /
 \ /Home Page: http://susis.ust.hk/~enoch                     \ /
  +------------------------------------------------------------+

2. libX.... problem!!!

3. Reading a directory and knowing which type of file am I reading

4. RootKit info

5. read a directory with read()

6. Semaphores and Processes

7. Timeout on read()?

8. RH 5.1, Cirrus 7543, X - help!

9. ad1: READ command timeout error message?

10. ncftp reading data time-out

11. timeout for read under SunOS 4.1.3

12. Howto timeout read from a socket?

13. read timeout