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

Vehicle tasks using semaphores, Gopher Gallery consists of a shopping mall ...

Gopher Gallery consists of a shopping mall and a cart ride that covers  the 150 acre habitat. There are m visitors and n single-person vehicles. Visitors  stroll around the mall at

Making the transition to client - server programming, Making the Transition...

Making the Transition to Client - Server Programming Making the transition to client - server programming is a significant effort. Client - server applications must be designed

What are the multithreading models, What are the multithreading models? ...

What are the multithreading models? There are three models:- a) Many-to-One model b) One-to-One model c) Many-to-Many model

Why do systems store the operating system in firm ware, Q. Why do several s...

Q. Why do several systems store the operating system in firm ware and others on disk? Answer: For certain devices such like handheld PDAs and cellular telephones a disk with

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

Explain the various types of computer systems, Explain the various types of...

Explain the various types of computer systems. Mainframe systems Large Number of CPU with Greatest Processing Power:  Huge Memory Capacity:  Increased Performance by s

Create a gantt chart for scheduling algorithms, Question: (a) The follo...

Question: (a) The following table (table 1.0) gives the length of the CPU burst time in milliseconds of processes P 1 to P 4 . Assume the processes arrived in the order P 1 ,

Explain the resource ownership and control, Explain the Resource Ownership ...

Explain the Resource Ownership and Control Operating systems are required to handle many different types of resources. CPU , memory, and I/O devices  are some of the varied sys

Design a android application, As mentioned earlier, the game engine will b...

As mentioned earlier, the game engine will be used as the base of developing the Go game for the Android. This includes improving logic of the game, design good graphics and optim

What are the system components of an operating system, What are the system ...

What are the system components of an operating system and explain them? a) Process management b) Main-memory management c) I/O management d) File management e) Seco

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