Interview Summary Operating Systems


#operating system

process

Process is a certain function independent of a dynamic procedure performed on a data set, the operating system is an independent unit of resource allocation and scheduling, is the carrier of applications running.

Interprocess communication

pipeline

Thread

A thread is a single program execution sequence control process, is the minimum unit of the program execution flow, the processor is a basic unit of scheduling and dispatching.

How many threads of a process to create

The number of threads and associated resources, with sufficient resources, can establish unlimited.

Context switching

It refers thread context switching with limited CPU resources, the limited execution time for each thread, a CPU needs to constantly switch from thread to another, i.e., the concurrent operation. The process is the same operation.

The difference between concurrent and parallel

Complicated by

When there are multiple processes in the operating system, but at the same time the system has only a (finite) CPU, then the system can not run multiple processes simultaneously, only the CPU time is divided into many segments, each of which runs only time a process.

Most operating system task scheduling is preemptive scheduling round-robin manner, that a short time after executing task forced to suspend execution of the next task, each task in turn executed. A short time task execution is called the time slice, the state of the task being performed called running, force a break to the next task after task execution time, the task is suspended in a ready state, waiting for the next part of its time slice 's arrival So that each task can be implemented, due to the very high efficiency of CPU time slice is very short, quickly switch between tasks, gives the impression that multiple tasks at the "same time", which is what we are said concurrency.

parallel

When the system has more than one CPU, then it is possible to operate the thread non-concurrent. When a CPU executes a thread, the other CPU can execute another thread, two threads and do not seize the CPU resources, may be performed simultaneously, we call such a manner parallel (Parallel).

Processes and Threads

the difference

  • The basic unit of the operating system when the process of resource allocation
  • The basic unit of thread scheduling and task execution
  • Independent of each other, but the thread under the process of sharing a unified process between process memory space
  • Thread context switching is much faster than the process context switch

In simple terms, each program runs under the system is a process, a process which each task is performed by one or more threads.

Memory Allocation

The system will assign at run time for each process different memory space; and thread, in addition to the CPU, the system does not (resources from their respective processes of resource thread used) to allocate memory for the thread, the thread group inter can only share resources.

Why should not the multi-threaded multi-process

Start the thread fast, quit fast, low impact on system resources.

Deadlock

cause

A blocking phenomenon of two or more processes generated in the competition for resources.

  • Mutually exclusive
  • Request and keeping conditions
  • Resources inalienable condition
  • Circular wait
  1. A process has other resources needed
  2. A while seeking resources occupied by other processes
  3. Resources belong to the inalienable resources

Solution

Destruction "request and hold" condition

  1. A one-time allocation of system resources all good
  2. Make a one-time request to process all the resources needed resources if the request can not be obtained immediately, let the thread waits.

Disadvantages: a waste of resources, often in the case of a request or process less resource

Destruction "inalienable" condition

  1. Set priorities for the process, high-priority process can deprive low-priority resource.
  2. If the requested resources are not available, then release the share of resources

Destruction "cycle wait" condition

System for each type of resource is assigned a number, each process sequentially numbered increasing resource request, release the opposite.

Deadlock Detection

  1. Requests and distribution relationship related resources conservation system
  2. Design algorithms to determine whether a deadlock state (request relationship to form a ring and occupancy)

Deadlock release

  1. Terminate the process deadlock:
  • All termination
  • Phasing out
  1. Resource deprivation law, deprived of a part of the process deadlock resources
Published 63 original articles · won praise 73 · views 70000 +

Guess you like

Origin blog.csdn.net/jjwwwww/article/details/99707013