COMP242 - SHELL
Code:
The shell: shell.c
Header file: shell.h
Example of use: register_test.c
What does it do?
It is a shell for xinu commands. It will receive the command, validate it, execute it and return the result. After each command, you are displayed the process table and ready queue.
Priority juggling
The shell is a xinu process like any other. You need to create and resume it in your initialize.c. It loops forever waiting for commands. The priority for the shell needs to be the lowest out of all the xinu processes. The shell executes only when all the other processes are not running. So, in order to use the shell, first you need to suspend all the processes.
How do I use it?
Compile and link the code. shell.c does all the work for you. You just need to follow register_test.c.
You can register three categories of elements:
- functions - it includes all the functions needed by the shell. Whenever you want to make xinu_create( function, ... ) you need to register the name of that function with the function address. To register the function you just call: function_register( function_name, &function ); You can see an example in init_func_table from register_test.c
- variables - it includes all the variables registered by the shell. Variables can be passed as arguments for xinu_create. To register a function you just call: variable_register( variable_name, &variable ); You can see an example in init_var_table from registered_test.c
- commands - it includes the xinu commands (system calls) that you are implementing. For the first assignment, I have registered the 5 system calls in shell.c, function init_comm_table. Therefore you do not need to be concerned with registering commands. The mapping name - system_call is:
- create - xinu_create
- suspend - xinu_suspend
- resume - xinu_resume
- kill - xinu_kill
- resched - xinu_resched
You can modify shell.c in order to rename any of them.
The shell will validate any of the commands and registered elements. It will print the result of the command. The result of the command and the signature is exactly the system call signature. The command arguments are separated by whitespaces.
Addendum
The code right supports just primitive data types for variables (int, long, char ...). It will be updated to support arrays.
Example calls:
create test_zero 81920 20 zero 1 0
- It creates a process that runs the function test_zero with a stack size of 81920, a priority of 20. The name for the process is 'zero'. It does not take any argument, so we have just 0 as end of arguments flag.
create test_one 81920 20 one 2 a 0
- It creates a process that runs the function test_one with a stack size of 81920, a priority of 10. The name for the process is 'one'. It takes one argument the variable a. The variable name needs to be registered.
kill 18
- It kills the process with the pid 18.
resched
For any questions contact the TA Stefan Zota( szota@cs.unc.edu )