0% found this document useful (0 votes)
16 views2 pages

Shell Input/Output Redirection Lab 7-3

The document outlines the objectives for Lab 3 in a computer science course, focusing on the implementation of command composition using unnamed pipes in a simple shell. It details how to extend the shell to support piping between commands, redirecting standard input/output to files, and executing multiple commands in a pipeline. Additionally, it provides resources for further reading on process creation and relevant system calls.

Uploaded by

miguel.s.lourenc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Shell Input/Output Redirection Lab 7-3

The document outlines the objectives for Lab 3 in a computer science course, focusing on the implementation of command composition using unnamed pipes in a simple shell. It details how to extend the shell to support piping between commands, redirecting standard input/output to files, and executing multiple commands in a pipeline. Additionally, it provides resources for further reading on process creation and relevant system calls.

Uploaded by

miguel.s.lourenc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DEPARTAMENTO DE INFORMÁTICA

Fundamentos de Sistemas de Operação 24/25

Implementation of a simple Shell (part II)


LAB 3

Objectives
Implementation of command composition via an unnamed pipe within a simple shell.

Command composition using a pipe


Considering the simple shell you implemented in Lab2, extend your code to support a simple pipe linking
two separate commands, e.g.,
cat ficheiro.txt | sort

In this case, the standard output of the command cat is redirected to the pipe, whereas the standard
input of command sort is redirected to the pipe. The output will show the result of sorting the lines in
file ficheiro.txt. The resulting process tree should be like:

sish

Input: keyboard Output: terminal


sish
sish creates forks, execs sort
pipe, forks itself,
exec cat

Figure 1. Launching two commands (in gray) communicating via a pipe

Redirecting the standard I/O (optional)


Extend your shell to execute commands with redirected output and/or input to files. For that purpose,
the user can write a command line such as
command arguments > filename

to inform that the standard output of the process running the command should be redirected to the file
filename. Similarly, a command line such as
command arguments < filename

must execute the command with its standard input redirected to the file filename.

Command composition using multiple pipes (optional)


Extend the solution supporting two commands communicating via a pipe to support a pipeline execution,
i.e. a sequence of multiple commands that communicate via pipes. For instance, given a text file of NOVA’s
students, named students.txt, where each line describes one student, including his degree program
acronym, the following pipeline:
cat students.txt | grep LEI | wc -l

1
will count how many lines include the “LEI” string, so, counts the number of students that are in “LEI”
(Licenciatura em Engenharia Informática).

Bibliography
• Section “Laboratory: Tutorial” of the recommended book:
http://pages.cs.wisc.edu/~remzi/OSTEP/lab-tutorial.pdf
• From the FSO recommended book, read the chapter about process creation available on
https://pages.cs.wisc.edu/~remzi/OSTEP/cpu-api.pdf
• On-line manual pages (use man command) for LibC and system call functions: fork, wait,
exit, execve, execvp, strcmp, open, close, pipe, dup2, dup, etc.

You might also like