Extended Find


Program description

The program 'exfind' is similar to 'find' and in addition defines type of file as well as sorts result file list.

Language - C
Platform - UNIX, POSIX compatible

Key points

Search - recursive call of function 'readDir()' (readir.c).

File type definition - creation of child process 'file' (defineType(), deftype.c).

Sort method - Sort by Distribution, Radix list sort using linked allocation (fileList_Sort(), filelist.c). Reference: Donald E. Knuth, The art of computer programming. V.3

Performance - process of file type definition is performed in separated threads, thus, searching thread does not stop its activity.

Thread synchronization - mutexes, conditions.

Algorithm description

The program starts from function 'main()' (exfind.c) which analyzes command line and creates main thread for search of files (showDir(), readir.c).

Function 'showDir()' performs initial initialization (creates mutexes for synchronization of access to array 'threads' (readir.c) and list of found files 'fileList' (filelist.c) as well as creates thread 'showStatus()' (stat.c) if set up option shows statistics and calls function 'readDir()' (readir.c) for initial searching subdirectory.

If function 'readDir()' found any subdirectory in current searching subdirectory, function 'readDir()' calls itself recursively for searching in this subdirectory. In case if 'readDir()' found file that meets search conditions, it creates new thread 'defineType()' (deftype.c) to define type of file, and adds this thread to array 'treads' (readir.c) in order to wait for finishing of all running threads (threadsWaitAndPrint(), readir.c) after search is finished.

Function 'defineType()' creates child process and reads from it (popen(), pio.c) in order to define file type and adds this file to list of found files 'fileList' (filelist.c).

Result list of found files can be sorted my method of Sort by Distribution (Radix list sort using linked allocation, Hooking-up of queues). All functions, which use 'fileList', use mutex 'lockFileList' (filelist.h) for locking.

Thread 'showStatus' (stat.c) works simultaneously with main thread. This thread waits for two conditions -- change of searching path and definition of file type. After updating status line it suspends again.

Source Code

exfind.c
deftype.h, deftype.c
filelist.h, filelist.c
pio.h, pio.c
readir.h, readir.c
stat.h, stat.c