Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab, you will demonstrate your knowledge of process creation and manipulation. The objective of the lab is for you to create your own
In this lab, you will demonstrate your knowledge of process creation and manipulation. The
objective of the lab is for you to create your own "shell". When you log into Loki, you are
running the bash shell. It will recognize a number of different "verbs" and using new processes,
will run those commands and display their output on your screen.
Your solution for lab # will be to create a C program which will accept a number of fixed verb
names of your choosing. These will be replacements for variations of normal bash commands.
Your program is to recognize the verb requested and create a process to run the equivalent bash
command. To create the process you MUST use the fork function and have the parent process
wait for it to complete.
Within the child process you MUST use one of the exec?? family of system calls to execute the
required bash verb with your selected parameters. You are not allowed to call aliases or functions
defined in your bashrc ask me why!
As an example, in my version I have created a verb called "jobtree". When I run my code and
type in "jobtree" at the prompt, it will produce the equivalent to the shell command:
ps o user:pid,stime,ttycmd U jacques forest
When I run jobtree in my shell, the C code will run the bash ps command followed by
parameters: o user:pid,stime,ttycmdU "jacques", forest".
I strongly suggest that you get your commands workingtested in bash before you port them into
your shell. It will help with debugging issues when things don't work later on
Don't forget to add in an extra command to exit your shell and return to the bash shell. As an
example I would add an extra verb like "logout" which would "exit" my C code and return to the
original bash process. Of course, logout shouldn't trigger a fork as this would just create an
extra process and not just exit.
Ensure that you wait for every child created by fork or you will be creating zombie processes.
Which, I will have to clean up They waste system resources so be vigilant. Do a ps ef grep e
$USER" before you log out and make sure you aren't leaving any zombies behind.
For this exercise, you are required to create your own verb equivalents. You are required to use
normal bash commands with parameters. Once you have selected or commands not counting
logout or help then use exec function call to execute the code.
Here are the ones I chose:
My shell's verb Bash equivalent
help None but prints out a help menu
diskuse du sch
drives df h t ext
chklog grep e $USER homeCOISsecure
jobtree ps o "user:pid,stime,ttycmdU $USER forest
logout Exits the shell
The help command will print out something like this change it to match your verbs:
Valid verbs are:
help: displays this text
lastmod number of days ago displays files modified on that day
diskuse shows the amount of disk being used in the current
directory.
drives Lists all of the ext mounted partitions as well as
their size and free space.
chklog username scans the access log for a specific username.
If not present, it dumps the whole log file.
jobtree username shows the processes running related to a specific
username.
logout Exits this shell and returns to your original shell.
NOTE: elements in square brackets are optional. Should you
omit them, the current username will be used.
EOT
In my implementation, if the username is not specified on the appropriate command lines, I used
the getenv command to retrieve the name of the currently logged in user the environment
variable USER If the "number of days" was not specified, I assumed a
You are required to hand in to the Lab drop box on BlackBoard, a well document and modular
program plus sample output in a log file showing the functionality of your program. Remember
to use your script from lab to zip up your work for submission
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started