Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 2: Find & Threaded Find Introduction This assignment will require you to write your version of the find command that will go through the

Lab 2: Find & Threaded Find

Introduction

This assignment will require you to write your version of the "find" command that will go through the filesystem looking for a file based on a string you pass to the command. The goal in this assignment is to build 2 versions of a find command, one will be a direct find that could use a recursive algorithm, and the second version will use threads to accomplish the same goal. You will start your program and pass a directory to start as well as the filename you are looking for. Once you find a file that matches the name you passed into the program you will output the absolute path of the file and do this for every match found.

You should start by building a fully working (non-threaded) version of the find command that works properly. Then copy that into a new program source and modify to add threading in the place of recursion.

To accomplish this lab you will write your program(s) in the C language and use the following libraries to do the directory reading as well as threading:

Directory operations:

  • opendir(), readdir(), struct dirent*, ...

File (if it is a directory or not)

  • stat(); // this will give the information if it is a directory or not by using the test for
  • S_IFDIR

Threading operations:

  • pthread_create(), pthread_mutex_lock(), .....

NOTE: When compiling with pthreads, you need to add the following in the command line to bring in the pthread library:

-lpthread

There are 2 goals in this assignment:

  1. Build a find command to utilize both operating system calls to search across a filesystem (or more) and identify where files that match your search string are and:
  2. Add threading to do the same thing, but then test the speed of both to see if the threaded one is faster than the non-threaded one.

Major components required in your shell

  1. Find functionality
  2. Pass in a directory to start searching from
  3. Pass in a string of a name you want to "find" in your filesystem on your machine
  4. Start at the given directory and for each file that matches the search string, print the absolute path + filename to the screen
  5. Recursive algorithm
  6. Create a way to search from the initial directory and for each directory found in a given directory, start searching that directory for filenames matching as well
  7. Each time you pull a filename from a directory entry you will need to test if it is a directory file or other kind of file and if it is a directory, you will need to open that directory and search through that one before going back to the previous directory
  8. Threading
  9. Take the "working" find program and add threading in place of the recursive algorithm
  10. Your goal here is to search many directories "at the same time"
  11. You will need to spawn detached threads and ensure they properly run without locks or any limitations to see how fast you can make this program vs the non-threaded versions
  12. Race condition
  13. In your program you will need to have a variable at "file scope" (global) that will act as the counter for how many files were searched.
  14. This variable will have the ability to turn off and on through another variable or #define (i.e. sometimes you want to run the program with it on, and others with it off). If you want to send a switch at the command line as with the --threaded below, that would be preferred, but not required.
  15. The main reason for this variable is to define a thread mutex lock if threading is imposed and the need to count is imposed as well. Other variations will not require this lock as there is no race condition.
  16. This count variable should start at 0 and increase by 1 each time a file is evaluated to see if it matches the passed in
  17. Ability to test the speed of each program
  18. With the use of a program called 'time' or 'timex' you will test the time it takes to find the same filename across your filesystem
  19. You will need to do this in a way that takes some time, so start at the root of your filesystem as this will take the most time to go through your entire directory/file tree.
  20. You will need to test 4 conditions
  21. No thread, no counting
  22. No thread, counting
  23. Threading, no counting
  24. Threading, counting

Find processing

You will run your program as either 2 different programs or with a command line switch to let the program run as normal or threaded. This can be done by accepting commands as follows:

$ myFind // This will run the normal program

$ myFind --threaded // This will run the threaded version

When the program is initiated the determination is made on whether to thread or not.

Grading for this assignment will be based on the following guidelines:

  1. Use "script" to capture your testing to a file. To use script, simply type script at a prompt (filename can be any name and if omitted the file will be called typescript). Once you have entered :

$ script

All I/O will be copied from the screen into the named file, and when you are done simply type "exit" to stop copying to the file.

  1. NOTE: exit will only stop script, not exit your session.Write a README.TXT file that describes the various commands that your shell will support. This file should contain pertinent information on how you designed your shell, list the commands and usage of the commands, what works and what does not work, as well as who worked on the project with you (no name = no grade).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions