Code Monkey home page Code Monkey logo

psearch's Introduction

PSEARCH

Psearch is a command line tool for searching a keyword in multiple text files and find the matched lines.

  • Psearch uses different Interprocess Communication (IPC) methods to optimize the search time:
    • fork (parent-child processes)
    • anonymous pipelines
    • shared memory
    • semaphores
  • Psearch uses standard POSIX API targeting Linux.

Compile

  • run make command in the project directory to compile all the programs.

Run

Psearch1

psearch1 uses parent-child paradigm to concurrently read each input file. The parent process creates child processes with fork(). Each child process gets an input file and finds the matched lines for given search keyword. Then each child process creates a buffer output file and prints the matched lines. Finally, the parent process reads all the buffer output files and writes the results into a single output file that is specified by the user.

  • run ./psearch1 <search_keyword> <input_file_count> <input_file1.txt> <input_file2.txt> <output_file.txt>
  • e.g., ./psearch1 love 1 input1.txt output1.txt

Psearch2

psearch2 uses parent-child paradigm to read each input file concurrently. Each child process gets an input file and finds the matched lines for given search keyword. Then each child process writes the results to anonymous pipes. Finally, the parent process reads all pipes and writes the results into a single output file that is specified by the user

  • run ./psearch2 <search_keyword> <input_file_count> <input_file1.txt> <input_file2.txt> <output_file.txt>
  • e.g., ./psearch2 love 1 input1.txt input2.txt output2.txt

Psearch3

This program uses master-slave paradigm. psearch3 only creates child processes and execute (exec()) them while psearch3slave reads the input file specified by the psearch3 and sends the results to the master. The communication between the master and the slaves is maintained by named shared memory(mmap()) with file mapping.

  • run ./psearch3 <search_keyword> <inputfile1.txt> <inputfile2.txt> <output_file.txt>
  • e.g., ./psearch3 love input1.txt input2.txt output3.txt

Psearch4

This program uses the same concept with psearch3 with some modifications.psearch4 uses POSIX shared memory without file mapping (shm_open()). psearch4 uses semaphores (sem_open()) to synchronize the shared memory usage of the master and the slaves.

  • run ./psearch4 <search_keyword> <inputfile1.txt> <inputfile2.txt> <output_file.txt>
  • e.g., ./psearch4 love input1.txt input2.txt output3.txt

Learning Outcomes

  • Interprocess communication on Linux with POSIX API:
    • parent-child: create child processes and concurrently solve problems with fork()
    • master-slave
    • pipelines, pipe()
    • semaphores
  • use shared memory to provide communication between processes:
    • shared anonymous mapping
    • shared file mapping mmap()
    • named and unnamed semaphores, sem_open()
    • POSIX shared memory, shm_open()
  • File management (e.g., CRUD operations)
  • measure execution times of concurrent processes.
  • memory management (still needs review :D)

psearch's People

Contributors

quelich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.