Understanding Operating Systems: Traps, Interrupts, System Calls, and Threads

Classified in Computers

Written at on English with a size of 3.94 KB.

What is the Key Difference Between a Trap and an Interrupt?

A trap is caused by the program and is synchronous with it. If the program is run again and again, the trap will always occur at exactly the same position in the instruction stream. An interrupt is caused by an external event and its timing is not reproducible.

Why is the Process Table Needed in a Timesharing System?

The process table is needed to store the state of a process that is currently suspended, either ready or blocked. It is not needed in a single-process system because the single process is never suspended.

Is the Process Table Needed in Personal Computer Systems With Only One Process?

No, it is not needed in a single-process system because the single process is never suspended.

What is the Purpose of a System Call in an Operating System?

A system call allows a user process to access and execute operating system functions inside the kernel. User programs use system calls to invoke operating system services.

Can the Client-Server Model Be Used in a Single-Computer System?

Yes, it can, especially if the kernel is a message-passing system.

Is it Important for a Programmer to Know Which Library Procedures Result in System Calls?

As far as program logic is concerned, it does not matter whether a call to a library procedure results in a system call. However, if performance is an issue, if a task can be accomplished without a system call, the program will run faster. Every system call involves overhead time in switching from the user context to the kernel context. Furthermore, on a multiuser system, the operating system may schedule another process to run when a system call completes, further slowing the progress in real time of a calling process.

Why Are Interrupt Handlers Written in Assembly Language?

Generally, high-level languages do not allow the kind of access to CPU hardware that is required. For instance, an interrupt handler may be required to enable and disable the interrupt servicing a particular device, or to manipulate data within a process' stack area. Also, interrupt service routines must execute as rapidly as possible.

Why is a Separate Kernel Stack Used When an Interrupt or System Call Transfers Control to the Operating System?

There are several reasons for using a separate stack for the kernel. Two of them are as follows:

  • First, you do not want the operating system to crash because a poorly written user program does not allow for enough stack space.
  • Second, if the kernel leaves stack data in a user program's memory space upon return from a system call, a malicious user might be able to use this data to find out information about other processes.

Does the Problem of Two Threads Waiting for Keyboard Input Occur in Single-Threaded Processes?

No. If a single-threaded process is blocked on the keyboard, it cannot fork.

Why Would a Thread Voluntarily Give Up the CPU by Calling Thread_Yield?

Threads in a process cooperate. They are not hostile to one another. If yielding is needed for the good of the application, then a thread will yield. After all, it is usually the same programmer who writes the code for all of them.

Can a Thread Ever Be Preempted by a Clock Interrupt?

User-level threads cannot be preempted by the clock unless the whole process' quantum has been used up. Kernel-level threads can be preempted individually. In the latter case, if a thread runs too long, the clock will interrupt the current process and thus the current thread. The kernel is free to pick a different thread from the same process to run next if it so desires.

What are the Biggest Advantage and Disadvantage of Implementing Threads in User Space?

The biggest advantage is the efficiency. No traps to the kernel are needed to switch threads. The biggest disadvantage is that if one thread blocks, the entire process blocks.

Entradas relacionadas: