Operating System - HP-UX
1753559 Members
6170 Online
108796 Solutions
New Discussion юеВ

Question about "piped find" behaviour: snapshot or buffered?

 
Enrico Venturi
Super Advisor

Question about "piped find" behaviour: snapshot or buffered?

Hello colleagues,
in my system there's a script which processes the files contained in a directory (there's a subtree under this directory); on this directory there're a lot of files; my script launches a "find $dir" command to have all the files in the $dir subtree; moreover there're other processes which create new files under $dir.
Therefore when the script starts in $dir there're (for instance) 50.000 files, after some while there're 55.000 file ....
My question is:
does the "find" make a snapshot of the $dir subtree content or it searches a set of files then searches again?
please note that the find output is piped with a command which processes the files ... i.e.
"find $dir | while read file
do
... processes $file
done"
if to process the $file the script need 4 sec.and in this meanwhile under the $dir 2 new files are created will the script end sometimes?
sorry if I wasn't clear enough

thanks
Enrico
3 REPLIES 3
Manish Srivastava
Trusted Contributor

Re: Question about "piped find" behaviour: snapshot or buffered?

Hi,

find(1) uses the depth first approach. It travesses the directory first and then searches the parents. The files and directories which will be processed by find depends on the time when it does an opendir(). Files and directories added after the opendir call are not considered for the find operation.

manish
Enrico Venturi
Super Advisor

Re: Question about "piped find" behaviour: snapshot or buffered?

ok but my question was a bit different:
the output of the find is piped to a command ... does the find waits for the command completion to complete the "navigation" across the subtree or the subtree is "frozen", a snapshot is taken then the output is produced?
Manish Srivastava
Trusted Contributor

Re: Question about "piped find" behaviour: snapshot or buffered?

Hi,

It takes a snapshot at the time when it opens the directory to read its content. If a file is created after the snapshot is taken it wont be considered by find.
As far as pipe is concerned find just dumps data in the pipe and if pipe is full then find waits to write to it. If the find output data is less than the pipe buffer find is not affected at all. If find is blocked on writing the data to pipe and during that time if files are created in directory which it has not yet opened for reading then those files will be considered by find once it writes data to buffer and continues processing.

HTH
manish