What is the context of a process
Operating Systems (Operating System Theory) - Chapter 3 - Processes and Threads
Contents of Dr. E. Nadobnyh
1) a process(Task) is an execution of the program in its own process environment. The process is a central concept of parallel processing in operating system theory.
2) One Process environment(Runtime environment, execution environment) consists of the process context and assigned resources.
3) a resource(Resources) can be hardware or an information unit. The following resources can be assigned to each process:
- Random access memory,
- other resources: open files, consoles, network connections, etc.
4) a Process contextis a detailed description of the process:
- Register contents,
- Address space description,
- Description of the assigned resources,
- Administrative data internal to the operating system.
5) a programis a procedural regulation for data processing.
- A program is part of the process environment.
- A particular program can be executed by several processes.
6) a job(Session, application) is a user request to the operating system.
- A job can consist of one or more processes.
- Jobs are independent and protected from others.
1) All software is organized as a set of processes.
2) The operating system creates an illusion for every process that it has the entire computer available to itself. This illusory calculator was realized through multitasking.
3) Every process does not notice any interruption, only the time delay.
4) Each process is protected from other processes.
1) a PCB* -Process Control Block (Process Context Block) is managed by the operating system to manage a process.
A PCB is a representation of a process and contains its process context.2) The Process tableis managed by the BS for the management of processes and contains PCBs from all processes.
It can also be implemented as a list.
Typical information in a PCB
1. Register contents:
- PC - Program Counter,
- PSW - Program Status Word,
- SP - stack pointer,
- general registers.
2. Information for storage management:
- Page table address,
- Base register contents,
- Boundary register contents,
- Addresses to code, data and stack segments of the process, etc.
3. Description of the assigned equipment:
- Information for file management: file descriptors, home directory, working directory, etc.
- Network connections,
- allocated devices, etc.
4. Process management data internal to the operating system:
- Process number (PID-Process IDentification)
- Process status, e.g. active, ready, blocked,
- Priority for scheduling,
- Processor time used since the start,
- Process number of the parent process (PPID, Parent PID), etc.
⇒ Demo 1.
Synonyms: process switch, context switch, context switch, process switch, task switch.
Two processes are involved in the process change:
- the suspended process that was active before the interruption, and
- the activated process that was inactive before the interruption. The activated process was selected by the scheduler.
Two resources are involved in the process change:
- CPU register and
- Random access memory.
Change of register contents
This switch consists of context backup and context recovery.
(1) At the Context protection(Context saving) register contents of the suspended process must be saved so that they can be restored later.
- The interrupt context is saved from the stack in the PCB.
- Other register contents are saved from the CPU in the PCB.
(2) At the Context recoveryregister contents of the activated process are restored, i.e. copied from the PCB to the CPU.
Change of memory contents
This change takes place e.g. in the computer with virtual memory.
When changing the process:
(3) some memory areas of the suspended process are swapped out and
(4) some address space areas of the activated process can be loaded from the hard disk to memory as required.
Creation and termination of the process
There are a few ways to create a new process:
- at system start, e.g. idle process,
- by user request, e.g. cmd console,
- by system call in the running process, e.g. fork in UNIX or CreateProcess in Windows,
- by system call for batch job, e.g. batch job.
There are a few ways to terminate a process:
- voluntary termination by system call, e.g. exit in UNIX or exit process in Windows;
- involuntary termination by the system due to the error, e.g. trap;
- involuntary termination by another process, e.g. kill.
⇒ Demo 2.
⇒ Demo 3.
A process goes through various states during its lifetime. A basic model contains three states:
1) Active (ongoing, running). The process owns the CPU. In a single processor system, only one process can be in this state at any given time.
2) Ready to calculate. The process is waiting for CPU allocation.
3) Blocked (waiting, blocked). The process is waiting for an event, e.g .:
- Expiry of a period of time which the process itself has commissioned, e.g. sleep,
- Allocation of a resource other than CPU,
- Message from another process.
Other process states are also possible in specific operating systems.
There are the following transitions between the states in the basic model:
(1) blocking. The active process releases the CPU because it is waiting for an event, e.g. for an input. The process is blocked.
(2) Displacement (deactivation, preemption, interruption of priority). The CPU is withdrawn from the active process, e.g. after the interrupt from the timer.
(3) Allocation (activate). The CPU is assigned to the process.
(4) Wake up (wakeup, unblocking). The reason for blocking is released because the resource is available.
Threads are parallel activities in a process.
Synonyms: threads, strands, light weight processes (LWP).
Basic idea: The entire computing work of a process is divided into several activities, which can run in parallel.
A text system (e.g. Microsoft Word) can be efficiently parallelized using four threads:
1) enter text,
2) check spelling,
3) design line / page breaks,
4) periodically create a backup copy on the disk. All four processes work together with a text document.
1) A thread is an execution of a part of a program.
2) Each thread belongs to a specific process.
3) Every process implicitly contains at least one thread.
4) Each process can generate any number of threads.
5) All threads of a process can be executed in parallel (pseudo-parallel). 6) Thread has states (active, ready to compute, blocked).
7) Thread has its own register set and its own stack.
8) All threads of a process have a common process environment, e.g. the same address space, the same open files, etc.
9) Each thread is not protected against other threads in this process.
Separation of resource management and processor management
The resources are shared between the process and the threads:
1) A process owns all resources except registers and stack.
2) Each thread has its own register set and its own stack. The CPU is not assigned to the process but to the threads.
3) The process owns the resources, the thread executes the code.
A thread context is put together in the so-called thread control block (TCB):
1) thread identification,
2) thread status (active, ready to compute, blocked),
3) priority for scheduling,
4) register contents,
5) Pointer to PCB, etc.
A PCB then does not contain any register content and is reduced accordingly.
Generation and termination of the thread
1) If a process is created, it provides an execution environment for threads. The code of the process is executed by a thread (primary thread) that is automatically created along with the process.
Each thread can create additional threads that belong to the same process.
2) Each thread can terminate itself or be terminated by another thread. If the primary thread is terminated, the entire process is terminated.
With process termination, all of its threads are also terminated.
⇒ Demo 4.
⇒ Demo 5.
Advantages and disadvantages of threads
1) Creating, terminating, communicating and changing the context of threads are much faster than with processes. This is where the term lightweight processes comes from.
2) The context change takes place particularly often. A thread context switch is approximately 100 times faster than a process context switch.
|Steps in changing context||Process change||Thread change|
|Change the storage management table||+||-|
|Replace memory areas||+||-|
|Emptying and reloading the cache||+||-|
3) Threads are not protected from each other and must be synchronized by programmers.
Multi-threading is an operating mode with several threads per process.
|Single thread systems||Multi-thread systems|
|One process system||MS-DOS||Java runtime system, e.g. JDK version 1.6|
|multitasking||Older UNIX variants||Windows XP, Solaris, Modern UNIX|
1) Kernel-level threads (KL threads) are managed by the operating system.
2) User-level threads (UL threads, user threads) are managed by the process. The operating system is not aware of the existence of UL threads.
- Advantage: The UL threads can be switched more quickly. For example, when measuring time for a VAX-UNIX system, the following relationships resulted: ULTh / KLTh / processes = 1/10/40.
- Disadvantage: If a UL thread becomes blocked (e.g. due to I / O), then all UL threads of the process are also blocked.
- Example: Fibers from Windows.
1) Java is a multithreading language.
2) Java threads are allocated to the CPU by the JVM.
JVM (Java Virtual Machine) is the runtime system for
3) Forms of Java threads:
- UL threads (Green Threads), e.g. JDK version 1.2 for Linux,
- KL threads, (native threads), e.g. Windows NT / 2000 / XP.
⇒ Demo 6
⇒ Demo 7
- Which nerve lowers the heart rate when stimulated
- Who flies PM Modis planes
- ELO was influenced by the Beatles
- What is logistic regression in r
- How many horses should I have
- What is an IP flood
- Who are your favorite Japanese authors
- Why do we have identities
- What is the importance of architectural design
- How can someone strengthen his speaking voice
- What is the best workout clothing brand
- How can a FIDIC contract be managed
- How can I become an anchor
- How can you determine your genotype?
- How do you spend your nights
- What is the formula for diluting stocks
- What content is interesting on YouTube channels
- Why don't you like Louis Pasteur
- Which Discworld novel should I read first?
- What is your opinion on autophagy
- What is the marginal utility of money
- Cat5 cable is faster than telephone cable
- As a Christian, Halloween is bad
- What do you advise to write texts