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

Why global variables are unacceptable, Why Global variables are unacceptabl...

Why Global variables are unacceptable Global variable, for instance, are unacceptable because they break the rules of self - containment. If all procedural components are runni

System bus and device speeds as the cpu speed increases, Q. Why is it impor...

Q. Why is it important to scale up system bus and device speeds as the CPU speed increases? Answer: Consider a system which carries out 50% I/O and 50% computes. Doubling-up

Explain the types of system calls, Explain the Types of System Calls Th...

Explain the Types of System Calls The major types of system calls are like this: a. Process Control: These types of system calls are employed to control the processes.

Linux, Discuss the risks of having a single root user

Discuss the risks of having a single root user

Define a state which is not a fundamental process state, Define a state whi...

Define a state which is not a fundamental process state Answer: Blocked state is not a fundamental process state

Malloc and calloc function, Note that the parameter for scanf doesn't need ...

Note that the parameter for scanf doesn't need the address operators & because name is an address. However the variable name has no defined space. This can cause problems within C

Requirements for solution of critical section problem, What are the require...

What are the requirements for solution of critical section problems? Mutual exclusion : If process p is implementing in its critical section then no other processes can be exe

Minor page fault , Minor page fault :I f the page is loaded in memory at t...

Minor page fault :I f the page is loaded in memory at the time the fault is started, but is not checked in the memory management unit as being loaded in memory, then it is named a

Quick, why we say " OS is a resource allocator" and “OS is a control progr...

why we say " OS is a resource allocator" and “OS is a control program"?

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