Lab 3 - The Shell, System Calls and IPC

In this lab, you will write a small program to illustrate the use of multiple processes and pipes in a shell utility. You will be required to submit the code you have written along with a short report answering a few questions.

Lab Material

  1. Slides
  2. Materials

Assignment

Write a program to simulate how the shell interprets the command:

find $1 -name '*'.[ch] | xargs grep -c $2 | sort -t : +1.0 -2.0 --numeric --reverse | head --lines=$3

This command will search through the directory given by the first argument for files ending in .c or .h and return the N files (where N is the third argument) which contain the most occurrences of the string given by the second argument. You can use the lab's Makefile to run a bash script with this command:

make find

You can use the finder.c file in the lab's archive as starter code for your program. When you have finished the program, use the build target in the lab's Makefile to compile it. The output of the correct program will match with the output of the finder.sh script which is also present in the lab's archive. You can use the test target in the lab's Makefile to check it against the expected output.


Please note that you must use execv system call (and not other members of the exec family e.g. execl, execve, execp etc.) to run a new program inside a child process after a fork call for the purpose of this lab.

Submission

The total grade for this lab will be awarded based on a demonstration of your submitted code [67%] and the in lab quiz [33%]. You should submit the following file on blackboard:

<STUDENT_ID>-ipc-lab.tar.gz

Please ensure that all the changes you have implemented in this lab are limited to the finder.c file. You can use the archive target in the Lab's Makefile to create





< Back to the Lab Home Page