CS3376 501503 Assignment 4 Due Date Submitted To ELea 209849

Cs3376 501503 Assignment 4due Date Submitted To Elearningutdallas

Write code to implement a pipeline of commands using pipes and fork system calls, with variations as specified:

- Model 1: Use one parent and two children to execute: “ls -ltr | grep 3376 | wc –l”.

- Model 2: Use one parent and three children to execute the same pipeline, with the parent doing nothing.

- Model 3: Create a dynamic program that accepts command arguments for creating a pipeline, with a maximum of 5 arguments and a minimum of 2, where the commands are passed as arguments at runtime.

Additionally:

- Write a Makefile that supports a two-step build process for the assignment.

- Package all source files and the Makefile into a ZIP file named as specified, following the format: __assign2.zip.

Paper For Above instruction

The assignment involves implementing Unix/Linux pipe pipelines in C programming, illustrating process creation, inter-process communication, and dynamic command execution. The goal is to understand how to create complex command pipelines programmatically using system calls such as fork(), pipe(), execvp(), and dup2(), emphasizing process management and IPC mechanisms in Unix/Linux.

Part 1: Static Pipeline Implementations

The initial phase requires modifying the provided static code to execute command pipelines such as “ls -ltr | grep 3376 | wc -l”. This demonstrates the fundamental understanding of creating pipelines involving two and three child processes. The implementation leverages multiple pipes, where each pipe connects consecutive commands in the pipeline, ensuring proper data flow through standard input/output redirection using dup2().

In the first implementation, "TwoPipesTwoChildren.cpp," a parent creates two child processes. The first child executes "ls -ltr" and writes its output into the first pipe. The second child reads from this pipe, executes "grep 3376," and writes to a second pipe. The parent then reads from the second pipe and executes "wc -l" to produce the final output. This approach ensures that each process manages its standard input/output appropriately, and all pipes are correctly closed after use to prevent resource leaks and deadlocks.

The second implementation, "TwoPipesThreeChildren.cpp," involves creating three child processes, each executing one command. After forking the first child for "ls -ltr," the main process creates a second child for "grep 3376," which reads from the first pipe, and a third child for "wc -l," reading from the second pipe. The parent remains idle and simply waits for all children to finish, illustrating a multi-process pipeline where each command runs concurrently and independently.

Part 2: Dynamic Command Pipeline

The second phase of the assignment involves creating a flexible program, "DynPipe.cpp," that constructs command pipelines dynamically based on user-provided arguments. This program accepts up to five command arguments, which it then executes in sequence by creating the necessary pipes and child processes at runtime. It verifies the number of arguments, ensuring they are within the acceptable range, and then builds the pipeline iteratively, connecting each command with pipes. This approach allows users to execute different command sequences without modifying the source code or recompiling.

This dynamic implementation emphasizes understanding of how to generalize pipe creation and process control operations, making the code adaptable to various command pipelines, reflecting real-world shell capabilities.

Furthermore, the assignment mandates writing a proper Makefile that handles a two-step build process, organizing the compilation of source files into object files before linking into executables. The project packaging should be done as a ZIP archive with a naming convention specific to the student, ensuring the inclusion of all source files, the Makefile, and documentation if needed.

Throughout the assignment, the focus remains on demonstrating mastery over UNIX process control, I/O redirection, inter-process communication, and dynamic command parsing, essential skills for developing robust command-line utilities and understanding process management at the system level.

References

  • Love, R. (2010). Linux System Programming: Talking Directly to the Kernel and C Library. O'Reilly Media.
  • Silberschatz, A., Galvin, P. B., & Gagne, G. (2018). Operating System Concepts. Wiley.
  • Kernighan, B. W., & Pike, P. (1983). The UNIX Programming Environment. Prentice Hall.
  • Stevens, W. R., & Rago, S. A. (2013). Advanced Programming in the UNIX Environment. Addison-Wesley.
  • BSD UNIX Manual Pages. (2023). https://man7.org/linux/man-pages/
  • Tanenbaum, A. S., & Woodhull, A. S. (2006). Operating Systems Design and Implementation. Pearson.
  • McKusick, M. K., & Neville-Neil, G. V. (2014). The Design and Implementation of the FreeBSD Operating System. Addison-Wesley.
  • Ritchie, D. M., & Kernighan, B. W. (1984). The C Programming Language. Prentice Hall.
  • Gagne, G., Silberschatz, A., & Galvin, P. (2014). Operating System Concepts Essentials. Wiley.
  • POSIX Programmer's Guide. (2008). The Portable Operating System Interface (POSIX).