CIT595 Flashcards
Which of the following are pushed onto the stack during a function call to remember the execution context of a process?
Program counter
Compute registers
File descriptor table
Program Counter
Compute registers
Because we are jumping to run another function, we need to remember the execution context of where we left off previously in the main function. The program counter and compute registers are necessary for this, the file descriptor table can be accessed throughout the program.
Is the following statement true or false? Select the best response. A process can jump to any location in the kernel via a system call.
True
False
False
For security reasons, it is not advisable for user processes to call into any arbitrary functions in the kernel. Otherwise, one process may arbitrarily jump to the kernel and read data that it is not authorized to read or call functions that results in security attacks that require root access. Instead, all system calls go through a limited number of entry points to kernel code, which are available as a limited number of system call functions to the user.
Is the following statement true or false? Select the best response.
In a function call, there is no need to transition to kernel mode.
True
False
True
Function code is part of the user’s application, and is thus accessible within user mode.
Which of the following statements about system calls are true? Select all that apply.
System calls are more expensive in terms of CPU resources compared to function calls.
System calls require context switching but function calls do not.
After a system call, the original system caller may not get to run immediately.
System calls require context switches, because they involve privileged instructions. Functions written by users do not require context switching. Context switching is expensive because the CPU must save the old process state and load in a new process. Because a new process gets a chance to run, the original system caller may need to wait to continue executing after the call is complete.
Which of these examples can cause a hardware interrupt? Select all that apply.
Clock tick or pulse
Completion of disk operation
Network message has arrived
Illegal memory access by user level process
All of these external events generate hardware interrupts that cause the operating system to react.
Is the following statement true or false? Select the best answer. Custom handlers are code in user space written to process signals sent to a process.
True
False
True
Every signal results in a default processing behavior, unless the user registers a custom handler in their code in user space
Every signal results in a default processing behavior, unless the user registers a custom handler in their code in user space
True
False
True
The operating system has a software component for doing signal relaying, because the operating system does not want to allow a process to send arbitrary signals to another process. The operating system essentially serves as a gatekeeper for all signals.
Which of the following correctly contrasts interrupt handlers and system calls? Select all that apply.
System calls have return values while interrupt handlers do not.
Context switch happens for system calls but not interrupt handlers.
Both interrupt handlers and system calls require context switching.
System calls have return values while interrupt handlers do not.
Interrupt handlers have parameters used by the OS, but no return values that are relevant to the user. Both system calls and interrupts are handled in kernel mode.
Which of the following signals cannot be caught or ignored by a process? Select all that apply.
SIGKILL
SIGINT
SIGSTOP
SIGKILL and SIGSTOP cannot be caught or ignored
Is the following statement true or false? Select the best answer.
Signals that are blocked by the operating system are lost forever.
True
False
False
If a signal reaches this filter and it’s slated to be blocked, then the signal will be buffered within the operating system. When there is an explicit command to unblock the signal, it will be relayed to the process.
Interrupts are only initiated by currently running processes.
True
False
False
Interrupts can be initiated by hardware, e.g. clock ticks, completion of I/O requests.
During a system call, a TRAP instruction occurs and executing the correct system call requires a jump to a specific address in OS address space, as indexed by the system call number.
True
False
True
Since a system call requires user mode to kernel mode transition, a TRAP has to occur. To avoid the TRAP jumping into any arbitrary location in the OS, it has to go through a dispatcher that figures out the right function call based on the system call number.
When executing a TRAP instruction during a system call, the CPU mode bit changes from supervisor to user.
True
False
False
It goes from user to supervisor mode.
A regular function call requires fewer CPU cycles than a system call (assuming both have the same code).
True
False
True
A system call requires trapping to kernel, context switching and updating some data structures in the kernel. Hence it requires additional CPU cycles.
Consider the following piece of code where a parent creates a child, a child creates a grandchild, and a grandchild creates a great-grandchild process Assume that parent, child (child_pid), grandchild (grandchild_pid), and great-grandchild (greatgrandchild_pid) have PIDs 100, 200, 300, and 400, respectively.
child_pid = fork()
if(child_pid != 0){
/execute parent code/
} else{
/execute child code/
grandchild_pid = fork();
if(child_pid != 0){
/execute parent code/
} else{
great_ grandchild_pid = fork();
}
Enter the value of the child_pid variable in the parent’s address space.
200
child_pid is equal to the return value of the parent’s fork() call which is 200.
Consider the following piece of code where a parent creates a child, a child creates a grandchild, and a grandchild creates a great-grandchild process Assume that parent, child (child_pid), grandchild (grandchild_pid), and great-grandchild (greatgrandchild_pid) have PIDs 100, 200, 300, and 400, respectively.
child_pid = fork()
if(child_pid != 0){
/execute parent code/
} else{
/execute child code/
grandchild_pid = fork();
if(child_pid != 0){
/execute parent code/
} else{
great_ grandchild_pid = fork();
}
Enter the value of the greatgrandchild_pid variable in the grandchild’s address space.
400
greatgrandchild_pid is equal to the return value of the grandparent’s fork() call which is 400.
Consider the following piece of code where a parent creates a child, a child creates a grandchild, and a grandchild creates a great-grandchild process Assume that parent, child (child_pid), grandchild (grandchild_pid), and great-grandchild (greatgrandchild_pid) have PIDs 100, 200, 300, and 400, respectively.
child_pid = fork()
if(child_pid != 0){
/execute parent code/
} else{
/execute child code/
grandchild_pid = fork();
if(child_pid != 0){
/execute parent code/
} else{
great_ grandchild_pid = fork();
}
Enter the value of the greatgrandchild_pid variable in the greatgrandchild’s address space.
0
When the grandchild calls fork(), a new process (greatgrandchild) is created. The return value in the greatgrandchild is 0.
Consider the following piece of code where a parent creates a child, a child creates a grandchild, and a grandchild creates a great-grandchild process Assume that parent, child (child_pid), grandchild (grandchild_pid), and great-grandchild (greatgrandchild_pid) have PIDs 100, 200, 300, and 400, respectively.
child_pid = fork()
if(child_pid != 0){
/execute parent code/
} else{
/execute child code/
grandchild_pid = fork();
if(child_pid != 0){
/execute parent code/
} else{
great_ grandchild_pid = fork();
}
Enter the value of the grandchild_pid variable in the grandchild’s address space. (Numeric answer question)
0
This has similar reasoning as in question 8. When a fork() call creates a new process, that within the new process, the return value of fork() is 0.
Which of the following is not an example signal that originates from a hardware interrupt?
Input from keyboard, network, or disk
SIGINT signal from one process to another
Clock pulse for updating system time
Illegal memory access
SIGINT signal from one process to another
Is the following statement true or false? Select the best answer.
STDIN and STDOUT are file descriptors made available to a process
True
False
STDIN and STDOUT are reserved as file descriptors which by default read from keyboard and output to the terminal. However, they can be overwritten.
Consider a command out > pwd where out is a valid text file, and pwd prints the current path. When you type it in a shell, what is the expected output? Select the best answer.
Prints the contents of out
Invalid command
The shell ignores out and just prints the current path
out > pwd is an invalid command since it starts with ‘out’ which the shell cannot interpret as an executable command.
Consider a command pwd < out, where out is a valid text file, and pwd prints the current path. When you type it in a shell, what is the expected output? Select the best answer.
Prints the contents of out
Invalid command
The shell ignores out and just prints the current path
The shell ignores out and just prints the current path
Since pwd is not expecting a STDIN, the ‘< out’ is ignored by shell.
Suppose you have a command that takes in an argument (e.g.sleep()) and you run “sleep 10 < file.txt”. When you type it in a shell, what is the expected output if the contents of file.txt is “100” and nothing else?
Sleeps for 10 seconds
Invalid command
Sleeps for 100 seconds
Sleeps for 10 seconds
The system call for sleep is not expecting another input argument, so the redirection is irrelevant and gets ignored.
What is the behavior of ls | more > out? Select the best answer.
ls runs to list all the directories. If more than fit into a page, the user has to press space to continue until all the files are listed. The output is stored in the file out.
ls runs to list all directories. Even if more than a page is needed, the user does not press any keys, and all the listed files are stored in the file out.
Throw an error
ls runs to list all directories. Even if more than a page is needed, the user does not press any keys, and all the listed files are stored in the file out.
This is somewhat surprising. Since the output of ls goes to a file, there is no real definition of a screenful of display, hence no user keys are needed.
What is the output of ls | pwd? Select the best answer.
We list all files in the current directory, and pwd is ignored.
Throws an error
The current path is printed out
The current path is printed out
The two commands run concurrently, but since the output of ls is used as input to pwd, it is not displayed. However, since pwd does not read from standard in, the output of ls is ignored and only the pwd command is executed.
Is the following statement true or false? Select the best answer.
A ctrl-C signal will be sent to an entire process group.
true
false
true
By definition, the option of grouping processes together allow us to send a signal to all.
Is the following statement true or false? Select the best answer.
A pipelines of processes A | B | C are in the same process group.
true
false
true
Whenever a pipeline of processes is implemented, the OS will always group the processes together so that they can receive common signals at the same time.
Which of the following commands are illegal or will cause the process to be stopped?
Select the best answer.
Is > out
Is > out &
cat &
Is | pwd &
‘cat &’ is illegal since a process cannot take in standard input in the background. Interesting, most OS will allow ‘Is > out &’ to happen. It just becomes distracting to have background processes generating output in the background.
Is the following statement true or false? Select the best answer.
When a process is stopped, a SIGCHLD signal is sent to the parent.
true
false
true
Whenever a process is stopped or exited, a SIGCHLD signal is sent to the parent.
Which of the following is a difference between processes and threads? Select all that apply.
Process creation is cheaper and faster than threads.
There can be many threads within a process.
Threads in the same process can communicate directly with each other by writing to the same memory location but processes communication involves the kernel.
Processes has better isolation than threads and one process is less likely to corrupt another process compared to two threads.
There can be many threads within a process.
Threads in the same process can communicate directly with each other by writing to the same memory location but processes communication involves the kernel.
Processes has better isolation than threads and one process is less likely to corrupt another process compared to two threads.
Is the following statement true or false? Select the best answer.
In a web server, creating a thread for each new request from a client and then destroying the thread after the request has been serviced requires less overhead than maintaining a thread pool.
False
Creating threads can be expensive so creating a new thread for each request will add a lot of overhead to the web server. It is more efficient to maintain a thread pool and to use a thread from the pool to service each request, returning the thread to the pool after the request has been serviced.
Which of the following are good uses of threads? Select all that apply.
A. Two different applications belonging to two different users, each running in a separate thread.
B. Web browser has several threads, each supporting a different task (e.g. image rendering, receiving requests from users, sending back HTML responses, etc.}.
C. An application that breaks up large amounts of data into small chunks for processing in parallel.
B. Web browser has several threads, each supporting a different task (e.g. image rendering, receiving requests from users, sending back HTML responses, etc.}.
C. An application that breaks up large amounts of data into small chunks for processing in parallel.
A is not a good way to use threads since processes provide better isolation. It is more desirable to have each user application run in its own separate process. B and C are good uses of threads as they both require running multiple tasks in parallel but yet isolation is not essential in either.