Что такое блок управления процессом
Перейти к содержимому

Что такое блок управления процессом

  • автор:

Operating System: Process and Process Management

Akhand Mishra

Process: In simple words, a process is an instance of an executing application. An application is a file containing a list of instructions stored in the disk (often called an executable file), in flash memory, maybe in the cloud but it’s not executing, it’s a static entity. When an application is launched it is loaded into the memory and it becomes a process, so it is an active entity with a program counter specifying the next instruction to execute and a set of associated resources. If the same program is launched more than once than multiple processes will be created executing the same program but will be having a very different state.

A process encapsulates all the data for running application, this includes the text, the code of the program, a data section, which contains global variables and data which are available when the process is first initialized. As text and the data are available when the process is first initialized they are called static states and are available when the process first loads.

The process also encapsulates the process stack which contains temporary data (such as function parameters, return addresses, and local variables), it is a dynamic part of the process state which grows and shrinks during execution in Last-in-First-out order. Suppose we are executing a function “A” and want to call another function “B” from this function, for this, we have to save our current state (state of function “A”) to the stack and jump to execute function “B”, after the execution of function “B”, the state of the previous function (“A”) from which the function “B” was called is restored from the top of the stack and function “A” can continue its execution from that vary instruction it had left (program counter was also saved).

A process may also include a heap, which is the memory that is dynamically allocated during process run time. Text and data, stack and heap are the types of state of the process.

Every single element of the process has to be uniquely identified by its address, so an OS abstraction is used to encapsulate all of the process data in an address space. The address space is defined by a range of address from V0 to some Vmax, and different types of process state will appear in different part of this address space. The address space from V0 to Vmax does not correspond to actual address space in a physical location, instead, they are virtual addresses. The memory management hardware and operating system components responsible for memory management like page tables maps these virtual addresses to actual physical addresses.

All process may not need all the address space, as there are can be many processes running at a time and we may not have enough space in the physical memory (i.e. in the RAM). In order to deal this situation, operating system dynamically decides which portion of address space will be present where in physical memory. Multiple processes may share physical memory by temporarily swapping some portion of their address space into the disk, this portion of address space will be brought back into the memory whenever needed. The page table maintains the mapping from virtual address to the physical address (RAM or Disk), it also validates whether a particular memory access request by a process is allowed to perform or not.

Before the execution of a process, its source code must be compiled, the compilation of the code results in the conversion of the high-level code to binary instructions, a register in CPU is maintained which indicates the address of the next instruction to be executed for this process, we call it Program Counter (PC). There are some other registers in the CPU which stores other information of the process like addresses for data or some status information. There is also a stack pointer which points to the top of the stack used by the process. To maintain all of this process for every single process an operating system maintains a Process Control Block (PCB).

Process Control Block (PCB)

A Process Control Block is the data structure that operating system maintains for every single process. The PCB must contain process states like program counter, stack pointer, all the value of the CPU register, various memory mapping from virtual to physical memory, it may also include a list of open files, information which is necessary for scheduling of the process like how much time this particular process has executed on CPU in the past and how much time it should be allocated to execute in the future.

A PCB is created at the very moment a process is created with some initializations like PC points to the first instruction that needs to be executed. Certain field of the process changes as the state of the process changes for example whenever a process asks for more memory, the OS will allocate more memory to the process and update certain values of the PCB like Page table, virtual memory limits, etc. Some values of the process change too often like the value of program counter which changes on the execution of every single instruction. As updating such changes in PCB can be an expensive task, their values are stored and updated in CPU registers which are very fast. However, OS updates all the values maintained by CPU registers to the PCB whenever that particular process is no longer running on the CPU.

Suppose OS is managing two processes p1 and p2, currently, p1 is running and p2 is idle, their PCBs are stored somewhere in the memory. The process p1 is currently running means that CPU registers hold the values that correspond to the state of p1. After some time suppose OS decides to interrupt p1, so OS will update all the state information fields of the process p1 including the CPU registers to the PCB of p1. After this the OS will restore the PCB of p2 from the memory, i.e. OS will update all the CPU register from the PCB of p2 and will start executing process p2. After some time if process p2 is interrupted the PCB of p1 will be restored and CPU registers will be updated from the value of PCB of p1 and p1 will start executing from the exact same point where it was interrupted earlier by the operating system. Each time this swapping is performed we call it context switch.

Context Switch

It is a mechanism used by operating system to switch execution from the context of one process to the context of another process.

Context switching is an expensive operation because of the number of instructions involved in loading and restoring values of fields of PCB from the memory. Also when a process p1 is executing a lot of its data is stored in the CPU cache as accessing the cache is much much faster as compared to accessing from the memory. When the data we want is present in the cache we say that cache is hot. When CPU will switch the context from process p1 to process p2, the process p2 will replace process p1’s cache with its own cache, so next time when the context will switch from the process p2 back to the process p1, p1 will not find its data in the cache and has to access it from the memory, so it will incur cache misses, so we call it cold cache.

Process Lifecycle

  • New: This is the initial state when a process is first started/created. In this state, OS will perform admission control, and OS will allocate and initiate process control block and some additional resources. After this, the state of the process changes to ready.
  • Ready State: The process is waiting in a queue to be assigned to a processor. Ready processes are waiting to have the processor allocated to them by the operating system so that they can run. A process may come into this state from Start state, from the running state or from the waiting state.
  • Running State: Once the process has been assigned to a processor by the OS scheduler, the process state is set to running and the processor executes its instructions. From this state, a number of things can happen, a running process can be interrupted and the context switch is performed and the running process will move back to the ready state. Another possibility is that the running process needs to perform some long operations like reading data from the disk, or waiting for some events, maybe some timer or taking input from the keyboard, at that time the process enters the waiting state, when the event occurs or the I/O operation completes, the process will become ready again. Finally, when the process completes all the operations in the program or when it encounters some error, it will return corresponding exit code and the process will be terminated.
  • Terminated State: Once the process finishes its execution, or it encounters some error, it is moved to the terminated state where it waits to be removed from main memory.

Process Creation

In the operating system, a process can create a child process. Hence all processes come from a single root in which a creating process is the parent process and the created process is the child of that process. Once the initial boot process is done the and operating system is loaded, it will create some initial process. When user logs into the system a user shell process are created, and when the user types in the command (emacs, nano, etc) then new process get spawned from that shell parent process. So the final relationship looks like a tree.

The mechanism for process creation

Most operating systems support two basic mechanisms for process creation

  • Fork: With this mechanism, the operating system will create a new child process with PCB and then it copies all the values of parent’s PCB to child’s PCB. After that, both the child and the parent continues their execution at instruction just after the fork call because both processes contain exact same values in their PCB which also includes program counter.
  • Exec: This replaces the child’s image and loads the new program. Child’s PCB contains the new initialized value and program executes from the beginning.

The mechanism of creating a new program is like calling the fork which creates a child process with exact same PCB as that of the parent and then calling exec which replaces the child’s image with the new program’s image.

CPU Scheduling

At a time there can be multiple processes waiting in the ready queue. The CPU scheduler determines which of the currently running process should be dispatched to the CPU for execution, and how long it should take.

In order to manage the CPU, the operating system must be able to preempt i.e. to interrupt the current running process and save is current context. This operation is called preemption. Then operating system must run the scheduling algorithm in order to choose the next process to run. And at last, once the process is chosen the operating system must dispatch this process to the CPU and switch to its context. OS must make sure that CPU is spending more time on running processes and not executing scheduling algorithm, dispatching, preempting or doing some other OS operations. Hence it is important to have an efficient design and as well as efficient implementation of the various algorithms involved for example scheduling. Also, efficient data structures that are required to represent waiting processes in the ready queue or any other information (like the priority of the processes, how long the algorithm ran in the past) that are relevant to make scheduling decisions.

Inter-process communication

Many applications are structured as multiple processes, so these multi processes have to able to interact with each other in order to achieve a common goal. As we have already studied that operating system isolates the process from each other in order to protect each other’s memory space, OS controls the amount of CPU each application gets. So some communication mechanism is required to build without sacrificing the protection. These mechanisms are called inter-process communication (IPC). Their task is to transfer data/info between address spaces without sacrificing the protection and isolation that OS provides. As communication can vary from the continuous stream of data sharing, periodic data sharing, a single piece of data sharing, etc so the IPC mechanism has to be flexible with good performance.

  • Message-Passing IPC: In this mechanism, the operating system establishes a communication channel (like shared buffer), and processes interact with each other by writing or sending data to the channel and reading or receiving data from the channel.
  • Advantage: Advantage of this mechanism is that OS manages both writing and reading data from the channel and provides APIs. So both process uses the exact same APIs.
  • Disadvantage: One disadvantage of this mechanism is that data has to first copy from sending process memory space to shared channel and then back to receiving process memory space.
  • Shared Memory IPC: In this mechanism, the OS creates a shared memory channel and then maps it to each process memory space, and then processes are allowed to read and write to the channel as if they would do to any memory space that is part of their memory space.
  • Advantage: The advantage of this process is that OS is not involved in the communication.
  • Disadvantage: As OS is not involved in the communication this mechanism does not support fixed and well-defined APIs for reading and writing data, so this mechanism is error-prone and sometimes the developers have to re-implement the code.

Summary

In this post, we learned how the processes are represented in the OS, we learned about the process abstractions like address space and PCB, we learned some key mechanism that operating system supports to manage processes like process creation and scheduling. We also learned about process lifecycle, context switching, and inter-process communication.

Блок управление процессом

Блок управления процессом (РСВ — process control block) — это объект, который определяет процесс для операционной системы и является структурой данных, сосредотачивающей всю ключевую информацию о процессе:

текущее состояние процесса;

уникальный идентификатор процесса;

указатели памяти процесса;

указатели выделенных процессу ресурсов;

область сохранения регистров (когда ОС переключает ЦП с процесса на процесс, она использует области сохранения регистров, предусмотренные в РСВ, чтобы запомнить информацию, необходимую для повторного запуска каждого процесса, когда он получит в очередной раз в свое распоряжение ЦП).

Концепция процессов является базовой для ОС UNIX. По сути порождение любого процесса — это создание некоторой виртуальной машины. Она имеет свое собственное адресное пространство, куда помещается процедурный сегмент и сегмент данных.

Дескриптор и контекст процесса. Системные данные, используемые для идентификации процесса, которые существуют в течение всего времени его жизни, образуют дескриптор (описатель) процесса. Множество дескрипторов образуют таблицу процессов — в современных версиях UNIX это несколько сотен процессов.

Дескриптор процесса содержит следующие параметры процесса:

расположение (адрес в памяти);

размер выгружаемой части образа процесса;

идентификатор процесса и пользователя.

Другая важная информация о процессе хранится в таблице пользователя (называемой также — контекст процесса), здесь записаны:

идентификационные номера пользователей, для определения привилегий доступа к файлам;

ссылки на системную таблицу файлов для всех открытых процессом файлов;

указатель на индексный дескриптор текущего каталога в таблице индексных дескрипторов;

список реакций на различные сигналы.

Обработка прерываний

Прерывание(interrupt) — это событие, при котором меняется нормальная последовательность команд, выполняемых процессором. Если произошло прерывание, то

управление передается ОС;

ОС запоминает состояние прерванного процесса;

ОС анализирует тип прерывания и передает управление соответствующей программе обработки прерывания.

Рассмотрим основные типы прерываний.

SVС(supervisor call instruction)-прерывания.

Инициатором этих прерываний является работающий процесс, который выполняет команду SVС, т.е. генерируемый программой пользователя запрос на предоставление конкретной системной услуги (например, на выполнение операции ввода-вывода, на увеличение размера выделенной памяти и т.п.). Механизм SVC позволяет защитить ОС от пользователей.

Инициируются аппаратурой ввода-вывода и сигнализируют ЦП о том, что произошло изменение состояния канала или устройства ввода-вывода, например, произошло завершение операции ввода-вывода, возникла ошибка или устройство перешло в состояние готовности.

Причинами таких прерываний могут быть различные внешние события, например, истечение кванта времени, заданного на таймере прерываний.

Прерывания по рестарту.

Эти прерывания происходят по команде рестарта ОС.

Прерывания по контролю программы.

Причинами таких прерываний являются различные виды ошибок, возникающих в выполняющемся процессе, например попытка деления на ноль.

Что такое процесс?¶

Процесс – это выполнение программы, которая выполняет действия, указанные в этой программе. Его можно определить как исполнительный модуль, в котором выполняется программа. ОС помогает вам создавать, планировать и завершать процессы, используемые процессором. Процесс, созданный основным процессом, называется дочерним процессом.

Процессами можно легко управлять с помощью печатной платы (блок управления процессом). Вы можете рассматривать его как мозг процесса, который содержит всю важную информацию, связанную с обработкой, такую ​​как идентификатор процесса, приоритет, состояние, регистры процессора и т. Д.

Что такое управление процессами? Управление процессами включает в себя различные задачи, такие как создание, планирование, завершение процессов и блокировка. Процесс – это исполняемая программа, которая является важной частью современных операционных систем. ОС должна распределять ресурсы, которые позволяют процессам обмениваться информацией и обмениваться ею. Он также защищает ресурсы каждого процесса от других методов и обеспечивает синхронизацию между процессами.

Задача ОС – управлять всеми запущенными процессами системы. Он обрабатывает операции, выполняя такие задачи, как планирование процессов и, например, распределение ресурсов.

Архитектура процесса¶

Вот схема архитектуры процесса

  • Стек: Стек хранит временные данные, такие как параметры функции, адреса возврата и локальные переменные.
  • Куча Распределяет память, которая может быть обработана во время выполнения.
  • Данные: содержит переменную.
  • Текст: текстовый раздел включает текущее действие, которое представлено значением счетчика программы.

Блоки управления процессом¶

Печатная плата является полной формой блока управления процессом. Это структура данных, которая поддерживается операционной системой для каждого процесса. Печатная плата должна быть обозначена целочисленным идентификатором процесса (PID). Это поможет вам хранить всю информацию, необходимую для отслеживания всех запущенных процессов.

Он также отвечает за хранение содержимого регистров процессора. Они сохраняются, когда процесс переходит из рабочего состояния, а затем возвращается в него. Информация быстро обновляется в печатной плате операционной системой, как только процесс выполняет изменение состояния.

Состояние процесса¶

Состояние процесса – это состояние процесса в определенный момент времени. Он также определяет текущую позицию процесса.

Есть в основном семь этапов процесса, которые:

  • Новый: новый процесс создается, когда конкретная программа вызывает из вторичной памяти / жесткого диска в первичную память / ОЗУ
  • Готов: в состоянии готовности процесс должен быть загружен в основную память, которая готова к выполнению.
  • Ожидание: процесс ожидает выделения процессорного времени и других ресурсов для выполнения.
  • Выполнение: процесс находится в состоянии выполнения.
  • Заблокировано: это временной интервал, когда процесс ожидает завершения события, такого как операции ввода-вывода.
  • Приостановлено: состояние приостановки определяет время, когда процесс готов к выполнению, но ОС не помещает его в очередь готовности.
  • Прекращено: Завершенное состояние указывает время, когда процесс завершается

После выполнения каждого шага все ресурсы используются процессом, и память становится свободной.

Блок управления процессом (PCB)¶

Каждый процесс представлен в операционной системе блоком управления процессом, который также называется блоком управления задачами.

Что такое блок управления процессом в Linux?

Блок управления процессом (PCB) — это структура данных, используемая компьютерными операционными системами для хранения всей информации о процессе. Он также известен как дескриптор процесса.

Что такое блок управления процессом с примером?

Блок управления процессом — это структура данных, которая содержит информацию о процессе, связанном с ней. Блок управления процессом также известен как блок управления задачами, запись в таблице процессов и т. Д. Это очень важно для управления процессами, так как структурирование данных для процессов осуществляется с помощью печатной платы.

Какая польза от блока управления процессом?

Блок управления процессом хранит содержимое регистра, также известное как содержимое выполнения процессора, когда его выполнение было заблокировано. Эта архитектура содержимого выполнения позволяет операционной системе восстанавливать контекст выполнения процесса, когда процесс возвращается в состояние выполнения.

Что такое печатная плата Какова ее роль?

Печатная плата, или PCB, используется для механической поддержки и электрического соединения электронных компонентов с использованием проводящих путей, дорожек или сигнальных дорожек, вытравленных с медных листов, ламинированных на непроводящую подложку.

Что такое процесс и контроль?

Управление процессом — это способность контролировать и настраивать процесс для получения желаемого результата. Он используется в промышленности для поддержания качества и повышения производительности. … Следовательно, эта простейшая форма управления процессом называется включением / выключением или контролем зоны нечувствительности.

Что такое блок управления процессом со схемой?

Блок управления процессом (PCB) — это структура данных, используемая компьютерными операционными системами для хранения всей информации о процессе. Он также известен как дескриптор процесса. Когда процесс создается (инициализируется или устанавливается), операционная система создает соответствующий блок управления процессом.

Почему в ОС используется семафор?

Семафор — это просто неотрицательная переменная, совместно используемая между потоками. Эта переменная используется для решения проблемы критического участка и для достижения синхронизации процессов в многопроцессорной среде. Это также известно как блокировка мьютекса. Он может иметь только два значения — 0 и 1.

Каковы два шага выполнения процесса?

Два шага выполнения процесса: (выберите два)

  • ✅ Пакет ввода / вывода, Пакетный пакет ЦП.
  • Срыв ЦП.
  • Вспышка памяти.
  • OS Burst.

Почему печатная плата полезна для многопроцессорной обработки?

Такая информация хранится в структуре данных, называемой блоком управления процессом (PCB). … Это важный инструмент, который помогает ОС поддерживать несколько процессов и обеспечивает многопроцессорность.

Каковы два применения ПХД?

Коммерческое использование печатных плат Трансформаторы и конденсаторы. Электрооборудование, включая регуляторы напряжения, переключатели, повторные замыкатели, вводы и электромагниты. Масло, используемое в двигателях и гидравлических системах. Старые электрические устройства или приборы, содержащие конденсаторы для печатных плат.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *