



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




In the last release of the mini-shell we will work on memory management and also, optionally, add the capability to execute pipelines.
First, we will replace malloc with your own memory management scheme based on the Buddy system algorithm discussed in class. Additionally, we will also add a few other minor features to the shell like redirection of input/output, ability to execute multiple commands per line and a new built-in history command.
A total of 15 points are reserved for the documentation and style of coding. Use your README file to communicate the structure of the files, the significant highlights of your project, test cases, the limitations and features, things that can still be improved etc.
; ls; sort < /etc/passwd > /tmp/log; who ls > /tmp/ls.out; sort < /etc/passwd;;; ls; ls -l /usr/bin | sort | wc -l ; date
dash: history 1 ls 2 w 3 cd 4 c 5 ls 6 w 7 rm plugin131_02.trace 8 ls 9 cs 10 ls 11 cd lab-solns/ 12 ls 13 cd p 14 ls 15 cd ../p 16 ls dash:
Use the GNU readline library for implementing the history command. Check the header file /usr/include/readline/history.h to find helper functions to implement the history command.
cmd < inputfile cmd > outputfile cmd < inputfile > outputfile For input redirection, try to open the file specified. If the file doesn’t exist or the user does not have permission to open it for reading the redirection should fail and a new prompt displayed. For output redirection, create a new file if it doesn’t already exist. Note that open creates a new file by bit-wise AND-ing the mode provided as an argument to the open() system call and the users umask. So if we want to create the output file to have read and write access for the user, and read access for the group and others, we can specify the mode as S IRUSR | S IWUSR | S IRGRP | S IROTH as an argument to open() and the open() will take care of restricting the permissions further depending on the users mask. The following session illustrates the above ideas. kohinoor:dash dash> ls > log dash> ls -l log -rw-r--r-- 1 amit faculty 264 Nov 13 12:26 log dash> chmod +x log dash> ls -l log -rwxr-xr-x 1 amit faculty 264 Nov 13 12:26 log dash> ls > log
Hints. Read Section 5.4 (Address Arithmetic) and Section 8.7 (Example–A Storage Allocator) from the C book by Kernighan and Ritchie to help you get started.
2.3.1 Basic Pipes (25 points)
The syntax for specifying a pipeline (in BNF) is as follows:
Here is an example of a three command pipeline.
cmd1 | cmd2 | cmd
Your implementation should be able to support any size pipeline (that is, you may have a constant that limits the size of the pipeline but to change this limit should require only changing this constant and nothing else in the code. Make this constant at least 10.)
2.3.2 Pipes and Signals (15 points)
The interrupt character (ctrl-c) should kill the whole pipeline if it is running in the foreground. It should not affect any pipelines running in the background.
If the user types the suspend character (ctrl-z under Linux) at the terminal, then the whole pipeline should suspend. Then the fg command should restart the pipeline. Make sure that you restart all the processes in the pipeline (and not just the last one!). Similarly, the bg command should continue the pipeline in the background.
2.3.3 Pipes and Redirection (5 points)
The shell supports both redirection and pipes in the same command. Redirection should be sup- ported only at either ends of the pipe. For example:
sort < /etc/passwd| wc last | sort | uniq -c | sort -rn > /tmp/log
2.3.4 Pipes in the Background (5 points)
The shell supports starting a pipeline in the background by having an ampersand after the last command. For example, the following pipeline runs in the background (and is not affected by signals).
ls | sort | wc & last | sort | uniq -c | sort -rn > /tmp/log &