Assignment 5, Solved
Part of
the homework for 22C:50, Summer 2003
|
The assembler also supports & (bitwise and) and | (bitwise or). These are well defined for integers, but neither the and nor the or operator makes any sense with relocatable operands, so it would seem best to simply forbid relocation of either operand.
# scr if ( "$1" != "" ) then echo $1 scr ${argv[2-]} endifHere is a call to this shell script:
scr this is a testPart a: What output does this script produce under the tcsh shell? You may need to use the man command to look at the manual for tcsh, but of course, you can also try running the script. this is a test
That is, each word of the parameter list to the script is listed on a separate line.
Part b: Explain the use of recursion in this script.
The script uses recursion in order to iterate through the parameter list. With each call, if there is a parameter present, it is output, and then, if there are any more parameters, they are passed on to the next recursive call (minus the first one).
Part a: The execve() service and the service suggested in the text differ in how control is transferred to the newly loaded program. What is the difference?
The suggested service in the text returns a pointer to the start of the loade code, allowing a later call to that code. The Unix service loads the new code and then immediately runs it, without allowing the caller any chance to intervene between loading and running the new code.
Part b: The execve() service and the service suggested in the text differ in the provisions they make for returning control from the newly loaded program to the original program after the new one finishes. What is the difference?
The Unix service makes no provision for returning control from the loaded program to the caller!