Principles of operating systems, Operating System

Assignment Help:

Objective - Tiny Shell (tish)

In this exercise you will write a small shell program to run different programs in foreground and background mode.

Background

Usually when you login on to the system the program that takes control and takes care of your requests is the "shell" program. In this exercise you will implement only a small portion of the shell capabilities.

Assignment

Your assignment is to build a program "tish" that will implement the following shell services:

  • Run programs in foreground and background;
  • List all processes that currently run in the background.
  • Kill a process running in the background.

The precise requirements are as following:

  • Your shell should give a user "tish>>" as a prompt;
  • There are two types of commands that "tish" should understand:
    • External commands: the command name is, in fact, the name of an executable file. When an external command is requested this means that the corresponding executable file should be run.
    • Internal commands: commands that are "built-in" in the "tish" shell. For example, the "bye" command does not correspond to any executable file. Instead, it causes "tish" to execute the exit system call. Below we specify which internal commands you are required to implement.
  • Execution mode for external commands:
    • Foreground: a command is given in the following form tish>> . In this mode "tish" does not return the prompt until the executable file that corresponds to the command finishes.
    • Background: a command is given in the same format as in the foreground mode, but the last parameter in the parameter list should be '&'. for example:
      tish>> emacs &
  • Example of running external commands:
    • tish>> emacs my_file.
  • List of Internal commands you are required to implement:
    • bye : terminate "tish". All background processes should be terminated. (Note that the real shell does not do this).
    • jobs : list of all background jobs in the following format: , in the order of creation.
    • kill :terminate the process corresponding to the specified pid by sending SIGTERM signal.

Recommendations and additional requirements:

  • You are required to use fork() and execvp(const char* file, const char* argv) system calls. execvp() is a version of the execve() system call in which the path and environment does not need to be specified. The file name should not! include a '/' char. If it does you should output a compatible error message. In this assignment you are required to deal with list of parameters no larger than 2. You are not required to check the type of the parameters you have received just to pass them on to the execvp() call in the right format.
  • You are NOT allowed to use the library function system() instead of fork/exec. This is because system() itself forks a new shell that forks the specified command. Using system() is absolutely prohibited in this exercise.
  • You may not assume that the user always specifies a correct input. For instance, the user may specify non-existent command name, or wrong parameters. Your program should print an appropriate error message. Note that empty or pure white space(s) command is not an error, and should be simply ignored and prompt should be repeated immediately
  • In the foreground execution mode a running process is terminated using the "Ctrl-C" key combination. Pressing this combination generates signal SIGINT that is sent to the control terminal process group. Since both "tish" and all its children are members of this group they have to take care of this signal. It should be handled differently in the main loop of "tish" (the one that provides the prompt and reads the user's input), and in a foreground child Namely:
    • Main loop of "tish" (father): ignores SIGINT, catches SIGTERM (may be sent by an outside application, e.g., tcsh);
    • Foreground child: default behavior, i.e., termination
  • When a process finishes, it enters the zombie state. A process will remain in this state as long as it father is alive. Since all external commands are children of "tish" and "tish" may be kept alive very long, the process table will eventually fill up. In this exercise you can ignore the fact that the number of zombie files in the system is limited.
  • "tish" command line is limited to 1024 characters
  • You may not assume correctness of arguments for internal commands (letters instead of numbers, negative numbers, etc. all should be checked)

System Calls and Functions List

  • fork();
  • execvp();
  • wait();
  • signal();
  • kill();
  • exit();

You may use "stdio" library functions in order to read user's input and to print the messages. You are advised to use string library functions, such as strtok() to manipulate strings.


 


Related Discussions:- Principles of operating systems

Give an overview of unix based file systems, Give an overview of UNIX based...

Give an overview of UNIX based file systems. UNIX and UNIX-like operating systems allocate a device name to each device, other than this isn't how the files on that device are

Briefly discuss on real-time scheduling, Briefly discuss on real-time sched...

Briefly discuss on real-time scheduling? It is divided into two types.  Hard real-time systems are needed to complete a critical task within a guaranteed amount of time. T

Protection, Can you please explain in easy words how input output protectio...

Can you please explain in easy words how input output protection works

Recognition of essential syntactic constructs by reductions, Recognition of...

Recognition of essential syntactic constructs by reductions, this task is carried out by Recognition of essential syntactic constructs by reductions, this task is carried out

Describe the state when you run an unlink operation, Describe when you run ...

Describe when you run an unlink() operation to remove a file on the ext3 file system. Be specific about what disk blocks have to be written where in what order. State your assumpti

Explain the procedure for handling the page fault, The procedure for handli...

The procedure for handling the page fault is as follows 1. We check the internal table to verify whether the reference was valid or invalid. 2. If the reference was invalid,

Introduction to paging, We will brie?y introduce paging to ?nish off this l...

We will brie?y introduce paging to ?nish off this lecture. When a process is loaded, not all of the pages are immediately loaded, since it's possible that they will not all be need

Describe the technique of packing, Describe the technique of packing. T...

Describe the technique of packing. The physical record size will not accurately match the length of the desired logical record and the Logical records may even differ in length

What are race conditions?, What are race conditions? Race conditions ar...

What are race conditions? Race conditions are problems that take place due to the sharing of the same file by several processes. In such a case none of the processes is able to

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd