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

Explain page traffic, The term ‘page traffic’ explains   Page traffic’...

The term ‘page traffic’ explains   Page traffic’ explains the movement of pages in and out of memory.

Essential properties of operating system, Essential Properties of Operating...

Essential Properties of Operating System 1. Batch: Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequen

unix script command and echo command, Objectives 1.    Login to UNIX ...

Objectives 1.    Login to UNIX system and logout 2.    Learn features of the vi editor and to use online help (main pages).  Gain experience using them to create a document

What is the resident set and working set of a process, What is the resident...

What is the resident set and working set of a process? Resident set is that portion of the process image that is actually in real-memory at a certain instant. Working set is th

What are the functions of virtual file system (vfs), What are the functions...

What are the functions of virtual file system (VFS)? a. It separates file-system-generic operations from their execution defining a clean VFS interface. It permits transparent

What are batch systems, What are batch systems? Batch systems are quite...

What are batch systems? Batch systems are quite appropriate for implementing large jobs that need little interaction. The user can submit jobs and return later for the results.

Explian integrating a request/response mechanism, Explian Integrating a Req...

Explian Integrating a Request/Response Mechanism Traditional application developers will need to develop a mechanism for communication between requesting (client) and respondin

Define the term operating system, Question: a) Define the term ‘Operat...

Question: a) Define the term ‘Operating System' and identify two goals of an operating system. b) What do you understand by Symmetric multiprocessing (SMP) and Asymmetr

Explain why sstf scheduling tends to favor middle cylinders, Explain why SS...

Explain why SSTF scheduling tends to favor middle cylinders over the innermost and outermost cylinders. The center of the disk is the location having the fewest average distanc

Define latency plus seek time, Define Latency plus seek time The total...

Define Latency plus seek time The total time to arrange a disk drive mechanism for a block of data to be read from is its Latency plus seeks time

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