1. (3 pts.) Assume that the thread_yield() is substituted by sleep(1) in
the spin-lock call. sleep(1) makes the current thread sleep for 1 second.
Answer: a) Is the new spin_lock() call going to work? b) If it does not work
explain why. If it does work, explain what would be the behavior of the new
lock.
2. (3 pts.) What is the impact of choosing a quantum time smaller than
the average process burst?
3. (3 pts.) What are the advantages and disadvantages of using user threads
vs. using kernel thrreads.
4. (3 pts.) Write the implementation of sema_wait and sema_post but instead of waiting use thread_yield and spinning. The implementation does not need to preserve the FIFO behavior of semaphores.
6. (10 pts.) Write the code for the function
char *strncat(char *dst, const char *src, size_t n); The srncat() function appends the string src at the end of the string dst. strncat() appends at most n characters from src. strncat returns a pointer to the resulting null-terminated string. |
char *strncat(char *dst, const char *src, size_t n) |
8. (10 pts.) Write the implementation of the procedure putenv() that adds an environment variable to the process environment. Assume that var_val is a string of the form VAR=VAL. If the variable already exists the old variable will be substituted with the new variable. |
extern char ** environ; |
9. (15 pts.) Implement a synchronized int array class. The class will have four methods: SyncIntArray(int n) is the constructor of the class that creates an array of size n and initializes the other variables. void add(int val) will add one value to the array. The value will be stored in any unused place in the array. add() will wait until there is space available in the array. int removeAny() will return the minimum value in the array. removeAny() will wait if the array is empty. Also you will implement the procedure int getMin() that will return the minimum element in the array but it will not remove it. getMin() will wait if the array is empty. |
|
10. (15 pts.) Write a function runPipe(command1,
command2, infile, outfile) that executes command1 and command2
connected through a pipe . Command1 and command2
are arrays of arguments that are NULL terminated. The output of command1
will be connected to the input of command2 using a pipe. The input of command
1 will be taken from infile and the output of command2 will go to
outfile. outfile will be created if it does not exist, or it
will be truncated it it does exist. Both command1 and command2 will run in
different child processes. The process calling runPipe will wait until the
child process that runs command2 terminates. See how runPipe is used in
main() below. |
int runPipe( char ** command1, char ** command2, char * infil, char * outfile ) |
11. (15 pts.) Implement the procedure char * scommand( char ** command, char * infile) that runs the command passed as argument and returns the output of the command as a string. The command executed takes as input the file in infile. scommand allocates enough memory to store the output of command. See how the procedure is used in main(). |
|