Showing posts with label Operating System. Show all posts
Showing posts with label Operating System. Show all posts

Thursday, September 30, 2021

What needs to be saved and restored on a context switch between two threads in the same process?

Operating systems questions and answers, OS University exam questions, what needs to be saved and  restored on a context switch between two threads in the same process

Question:

What needs to be saved and restored on a context switch between two threads in the same process?  What if the two threads are in different processes?

 

Answer:

Context switch saves the state of a process or thread. This is to enable the process to resume execution later.

The registers (integer and floating-point), program counter, condition registers (status register or flag register), and any other execution state for a thread must be saved between context switches. Need to reload the registers, stack pointer, and program counter from the TCB of the new thread.

When the threads are from different processes, need to not only save and restore what was given above, but also need to load the pointer for the top-level page table of the new address space.  (Note that this top-level page table pointer from the old process does not need to be saved since it does not change and is already contained in the process control block (PCB)).

 

******************
Related Questions:

 

 

 

Purpose of system calls in an operating system

Operating systems questions and answers, OS University exam questions, write down the purpose of systems calls in OS

Question:

Explain the purpose of system calls in an operating system with an example.

 

Answer:

System calls allow user processes to request service from the kernel. In particular, they allow the user to ask the kernel to do something for the user process that is not allowed to do for itself because of protection or sharing concerns. In simple terms, system calls are the programming interface to the services provided by the operation system.

Example:

User processes are allowed to access some files but not others, and have read access to some file and read/write access to others. Thus the write () system call allows a user process to ask the operating system to write some data to a file. Before performing the operation, the OS verifies that the user has write access for that file.

In addition, the system calls abstract away the details of the hardware and the lower level software, providing a clean, uniform, and portable application programming interface to the user processes.

 

******************
Related Questions:

 

 

 

 

 

Why the scheduling of processes and threads on a multi-processor system is more complicated

Operating systems questions and answers, OS University exam questions, scheduling of processes and threads in a multiprocessor is complicated than single processor

Question:

List the reasons why the scheduling of processes and threads on a multi-processor system is more complicated than scheduling them on a uni-processor system.

 

Answer:

Concurrently executing processes may require access to shared data. This may lead to inconsistency. Hence, we need mechanisms to ensure data consistency.

More than one processor is available, so load-balancing is an issue.

Difficult to debug of non-deterministic execution sequences due to the unpredictable rate of progress of threads executing on different processors (due to differences in processor speeds).

Cache affinity needs to be considered in CPU scheduling decision.

Modern CPU architectures have many subtle features, such as multi-core, that are hard to exploit properly in user-level programming.

Scheduling is two dimensional in multi-processor system. Hence, the scheduler has to decide which thread to run first and which CPU to run for that thread. So, the extra dimension makes scheduling too complicated.

 

******************
Related Questions:

 

 

 

 

Featured Content

Multiple choice questions in Natural Language Processing Home

MCQ in Natural Language Processing, Quiz questions with answers in NLP, Top interview questions in NLP with answers Multiple Choice Que...

All time most popular contents

data recovery