Your solution for lab #4 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:32,pid,stime,tty,cmd -U jacques --forest When I run jobtree in my shell, the C code will run the bash ps command followed by 5 parameters: "-o", " user:32,pid,stime,tty,cmd", "-U", "jacques", "--forest". I strongly suggest that you get your commands working/tested 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.
Your solution for lab #4 will be to create a C
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:32,pid,stime,tty,cmd -U jacques --forest
When I run jobtree in my shell, the C code will run the bash ps command followed by 5
parameters: "-o", " user:32,pid,stime,tty,cmd", "-U", "jacques", "--forest".
I strongly suggest that you get your commands working/tested 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.
Step by step
Solved in 5 steps with 3 images