Question: In C, Create own shell!! You shell will have functionality to run both built commands as well as other executables, manage child and parent relationship,

In C, Create own shell!! You shell will have functionality to run both built commands as well as other executables, manage child and parent relationship, and run in a separate Linux namespace.

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

Executable program on disk

Built in command

Neither - display command not found and/or any other errors

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

Manage child/parent processes (dont create a process)

Use the proper exec() function to start new processes

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

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 is Docker (www.docker.com). 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)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!