Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ or C language Operating system programming 1. The goal of this programming a

ID: 3745922 • Letter: C

Question

C++ or C language Operating system programming

1. The goal of this programming assignment

The primary goal of this assignment is to understand and gain some familiarity with the system call interface in Unix Environment. In this assignment you will be implementing your own command line interpreter like a Unix shell program. YOU ARE NOT IMPLEMENTING COMMANDS! YOUR program should just FORK off programs and EXECUTE them.

2. Requirements

(1) Programming language: You have to use either C or C++ to develop your program.(2) Running Environment: Your program should be compiled at CSEGRID and be able to be tested without errors.

3. The implementation details

.    (1) Backgrounds: The command line interpreter, called a shell, is an application program that gets commands from a keyboard and uses the system call interfaces to invoke OS functions.

.    (2) Your shell should support followings:

(a) Support exit or stop your shell commanda) Example(s): exit

(b) Support commands with no arguments.a) Examples: “ls”, “pwd”, “whoami” and “hostname”

(c) Support commands with arguments:a) Examples: “ls –l”, “ls –fx”, “ps –aux” ,“date –u”, “cd directory”, etc.

(d) A command, with or without arguments, whose output is redirected to a file a) Examples: ls > foo, ls -Fx > foob

(e) A command, with or without arguments, whose input is redirected from a file a) Examples: sort < testfile

(f) Supporting a sequence of programs that communicate through a pipe.a) Examples: ls | wc

(g) Display error messages if the typed command has errors or can’t be found

4. Hint

Your shell should isolate itself from program failures by creating a child process to execute each command specified by the user. For example, the “tar cvf cli5678 program1” command is executed by a child of the process executing the shell, myshell.

% tar cvf cli5678 program1 myshell

You might consider the following functions to build myshell:

.     (1) Printing a prompt – when myshell is begun, it display its own string as its own prompt. For example, “myshell> ”

.     (2) Getting command line – To get a command line, the shell performs a blocking read operation so that the process that executes the shell will be blocked until the user types a command line in response to the prompt. When the user enters the command, the command line string should be returned to the myshell.

.    (3) Parsing the command: Take the user command and divide it into command and arguments as well as checking errors.

.    (4) Finding the file – The shell provides a set of “environment variables” for each user such as “PATH”. The PATH environment variable is an ordered list of absolute pathnames that specifies where the shell should search for command files.

.    (5) Create a child process and launch the command – Once the command and arguments are prepared, create a child process to execute the command with its arguments and wait until the command is completed.

Explanation / Answer

In order to create a shell program for this, we first create a child process and then launch the command. We then prepare the arguments and the commands needed. Once done, we then create a child process in order to execute the command generated along with its arguments and we wait till the command completes.

When creating and executing a shell program, many steps have to be kept in mind starting from the login process after the user has been authenticated. However, the shell initializes its data structures only then it is ready to work. It prints a prompt in the very initial few characters of the first line after clearing the 25-line display.

We know that the Bourne shell (sh) prompt is - $.

The C shell (csh) prompt is - %.

The shell now waits for the user to type a command line in response to the prompt entered. The command line can be a string like -

    $ ls -al

It is terminated with newline character (' '.)

Whenever the user enter a command line, it is the shell's job to have the OS execute the command which is embedded in the command line.

Steps to be followed are –

Fork – Creates a new process. After it has been called 2 processes execute the statement after fork in their own address space – parent and child.

Execve – This is used to change the program that is currently being executed. Syntax is as follows - execve(char *path, char *argv[], char *envp[])

Wait – This system call is used by the process to block itself till the signal comes from the kernel for the process to execute again.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote