OS Laboratory Assignment 3 |
Command Interpreter |
Date of assignment distribution: August 10, 2006 Deadline for submission: August 27, 2006
A command interpreter is a program which takes the commands from the user as input and executes various programs/utilities appropriate to the issued command. A classic example: [amit@hobbs work]$ ls oslab1 oslab2 oslab3 a.out [amit@hobbs work]$
Write a C program which interprets the following standard linux commands: 1. pwd: prints the present working directory 2. cd: changes the current directory to the desired directory given as argument 3. ls: lists all the files in the present working directory 4. mkdir: creates a new directory 5. cp: copies a source-file to a given destination (both are given as arguments) 6. running an executable from the shell: fork to create a new process which runs the executable. Also take care of the arguments of the executable, if any. (Hint: Check out the ‘exec’ family of functions. e.g. execl’, ‘execlp’, ‘execv’ etc) 7. redirection: redirect the output of one process to another file. e.g. ./a.out > data.out 8. pipe: the output of one process is fed to the input of another process. e.g. ./a.out | ./b.out (Hint: Check out the use of ‘dup’ and ‘dup2’.)
On executing the executable there should be a command prompt like “myshell>” appearing in the shell. [amit@hobbs work]$ ./a.out myshell> This prompt should be able to take the above-mentioned commands from the user, execute it and again return with the same prompt. The shell should terminate your process and return its original prompt on command “quit” or “exit”. myshell> exit [amit@hobbs work]$ The prompt should return some error message on unknown commands. Do not internally call the linux utilities from your program. For your reference you can consult the manual pages and the following link for GNU C-functions (http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html). For viewing the manual pages do the following. For example, to get the usage of ‘execv’, [amit@hobbs work]$ man execv
|