Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help by writing the code I am new to this programming. Just I need help with all writing the code Thank you! Someone alredy

Please help by writing the code I am new to this programming. Just I need help with all writing the code Thank you!

Someone alredy tried but is not quite clear to me and I didn't understand it again help me.

This assignment will require you to write your own mini-shell.. Of course, your shell will not be as feature rich as ksh, bash, or csh, but your shell will have functionality to run both built commands as well as other executables, manage child/parent relationship, and run in a separate Linux namespace. To write your own shell, you will need to start with a C program that will prompt the user for input and accept in a number of arguments from a command line. There is a requirement to use Linux as the Linux namespace functionality only exists in Linux. The commands entered will be accepted into your shell and then processed to understand if it is a built in command or something that needs to be executed via fork/exec

(NOTE: No use of system() function). The interaction with your shell should be just like the standard shells. What I mean by this is to have a good usage statement returned if the arguments passed to the shell are not correct, and when there is an error you should send back a useful error, and not exit the shell, just continue.

Major components required in your shell

1. Prompt / collect from a command line process. Evaluate whether the command is:

a. Executable program on disk

b. Built in command c. Neither - display command not found and/or any other errors

2. Process execution - utilizing fork/exec to create a new process and successfully spawn a child process and execute another program as that process

a. Manage child/parent processes (dont create a process)

b. Use the proper exec() function to start new processes

3. Spawn new namespace using clone() - Namespace (clone function) is an element to Linux and allows a version of virtualization without the need for a hypervisor - functions in the namespace are defined below

4. Code & functionality - properly written code inclusive of a good main() function, usage statements, ability to send in different commands (strings) that are parsed properly, code does not crash, etc.

Process Execution A shell would not be of much use without interaction. Your shell will work like the standard shells in how it executes commands. There are at least 2 kinds of commands that the standard shells use

1. executable commands

2. built in commands. Your shell should have a built in command that is not a standard UNIX command (programs on disk), that work in the shell. When a parent kicks off a child process, the parent will need to wait for a signal from the child process on exit so that the child process does not become . There are many pieces to a shell, and trying to write one is not a simple task. I would suggest taking time to write a piece at a time, and implement some version of source control to minimize the loss of code per iteration of your program. Please do not worry about all of the details of a shell, I am just looking for a working shell that does all of the above sections. If you have questions about the depth of your shell, or how detailed it should be, please contact me for further instructions. New Process Namespace Namespaces allow for virtualization and sharing of spaces between parent and child processes. This is a part of the Linux operating system since 2008 that allows for the creation of different models to create containers for software applications. The most popular version of Linux namespaces . Your task for this lab is to create the option inside your shell through built in commands to move your shell into a container. The options for different containers can be added together in

a clone() or clone2() call. Here are some of the options:

CLONE_NEWIPC - New namespace for IPC

CLONE_NEWUTS - Setup new hostname and domain

CLONE_NEWUSER - User and group changes

CLONE_NEWNET - New network namespace

CLONE_NEWNS - New mount namespace When using a clone() function, you will have the ability to run another function. To test your clone() call, you will need to be able to demonstrate the change, and the best way to do that is to spawn another shell to look around at what changed. The best way to do this is to spawn another shell to be in the cloned process so that you can see what changed. You will need to run the commands below before entering your clone, and then again in your clone to show the difference between the namespaces. Once in your sub-shell you will test the clone options with the following commands (as examples):

CLONE_NEWNET

sh-4.1# ip link CLONE_NEWNS

sh-4.1# readlink /proc/[your process id]/ns/mnt

E.g. if your PID is 2324, then the command would be readlink / proc/2324/ns/mnt You can find your process ID with the ps command

(look for your shell name) as in: sh-4.1# ps PID TTY TIME CMD 2249 pts/1 00:00:00 bash // This is my default 4381 pts/1 00:00:00 sh // This is my sub-shell - to test clone 5236 pts/1 00:00:00 ps sh-4.1# CLONE_NEWIPC / CLONE_NEWUSER / CLONE_NEWUTS All of these clone arguments can be seen by looking in the /proc directory. Look under /proc/$$/ns/* for the filename (number). Note it change when you pass in one of the arguments above for IPC/USER/UTS. NOTE: In the shell, the $$ will print out your Process ID (PID) Namespace Requirements 1. Must run on Linux >= 2.6.25 2. Must run as root (at least for some clone calls) You will need to create commands or a single command with arguments that will identify how you would invoke one or more of the above options. It is suggested that you create a single built in command that will take one or more options listed above. To test the different options listed you will need to have functions that will be called with the clone() call that allow you to show what has been done to the process. An example is: Option : CLONE_NS - this will create a new mount namespace Test : function will need to be a sub shell to allow a user to run commands like ls, cd, pwd to show where they are in the mount namespace. Option : CLONE_NEWNET - this will create a new network namespace Test : In the function, run a command to show the ip address(es) of the network cards known to the process (will be different than your real network addresses / cards. Have fun with this program, it should be rewarding, and help you comprehend processes and some operating system structures we have discussed in lecture. I will be looking for style and testing as part of your grade. Please take time to comment your code well, and run some valid and useful test cases (remember that a good test case does not necessarily test how the code should work). Grading for this assignment will be based on the following guidelines: 1. Use script to capture your testing to a file. To use script, simply type script at a prompt (filename can be any name and if omitted the file will be called typescript). Once you have entered script, all I/O will be copied from the screen into the named file, and when you are done simply type exit to stop copying to the file. 2. NOTE: exit will only stop script, not exit your session.Write a README.TXT file that describes the various commands that your shell will support. This file should contain pertinent information on how you designed your shell, list the commands and usage of the commands, what works and what does not work, as well as who worked on the project with you (no name = no grade). 3. GIVE CLEAR INSTRUCTIONS ON USING THE SHELL IN YOUR README.TXT Basic 1. Shell prompt 2. Quitting the shell [quit] Built in command that your shell will support 1. clone [ argument ] e.g., MyShell > clone net Shell usage 1. The shell should exit gracefully at all conditions with proper error messages. 2. Should give proper usage statements on improper commands or arguments to commands Specific testing for grading Shell Execution This should be very straightforward. You will make a determination if the command entered is an executable or a built in command such as clone, vs an executable like ls. If it is an executable, you will need to fork/exec the executable, and if it is a built in, then call the appropriate code/block to execute the built in command.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Decisions Based On Data Analytics For Business Excellence

Authors: Bastian Weber

1st Edition

9358681683, 978-9358681680

More Books

Students also viewed these Databases questions

Question

How We Listen?

Answered: 1 week ago