Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Processes and threads of operating system notes

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Background

7 themes of operating system design:

1. Process description and control

two。 Memory management

3. Dispatching

4. Icano and file management

5. Concurrent and distributed systems

6. Embedded system

7. Safety

The operating system uses the hardware resources of one or more processors to provide a set of services to the system users and manages the auxiliary memory and Ihand O devices on behalf of the users.

Classification of CPU interrupts:

1. Program interrupt

two。 Clock interrupt

3. I PUBO interrupt

4. Hardware failure interrupt

DMA: direct memory access

Overview

Three important interfaces of a typical computer system:

1. Instruction system architecture ISA

two。 Application binary interface ABI

3. Application programming interface API

Process

Three parts:

1. An executable program

two。 Relevant data needed by the program (variables, workspaces, buffers, etc.)

3. The execution context of the program, also known as the process state. The context includes all the information that the operating system manages the process and the processor needs to execute the process correctly, including:

1. The contents of the processor register, 2. Priority multithreading technology of process

A process executing an application is divided into multiple threads that can run at the same time.

Thread:

A dispatchable unit of work that includes the processor context and its own data area in the stack. Sequential execution and interruptible.

Process:

A collection of one or more threads and related system resources.

Multithreaded switching involves less processor overhead than switching between different processes.

Microsoft

Window 3.0, developed in 1981 based on MS-DOS, employs Dave. Cutler developed the NT kernel based on the VAX/VMS operating system in 1989.

UNix

A brief introduction to the main kernel components:

Signal (Signal): the kernel notifies the process by signal.

System call (System Call): a process requests system services through a system call. There are hundreds of system calls, which can be roughly divided into six categories: file system, process, scheduling, interprocess communication, sockets, and others.

Processes and schedulers: create, manage, and schedule processes.

Virtual memory

File system

Network protocol

Character device driver

Block device driver

Network device driver

Traps and mistakes

Physical memory

Interrupt

Linux Vserver

Chroot provides file system isolation.

Chcontext assigns a new security context to provide process isolation

Chbind locks the resulting process and its children to a specific IP address, providing network isolation.

Capability, which provides root isolation.

Process

The process can be uniquely represented by the following elements:

Identifier

Status

Priority

Program counter

Memory pointer

Context data

Ipaw O status information

Accounting information

A processor has at most one process executing at any one time.

The five states of the process:

-New, environment ready, but not in memory

-ready

-run

-blocking / waiting, Istroke O blocking, waiting for resource or another process information

-exit

-for virtual memory: pending state

The operating system maintains four different types of tables:

Memory: tracking internal and external memory

ICandle O: iUnip O statu

File: file status, most of which may be maintained and used by the file management system

Process:

Process status of Unix

User mode operation

Kernel state operation

Ready to reside in memory

Sleep, stay in memory, wait for a certain time, a blocking state

Ready to be swapped

Sleep, be swapped

The preempted process returns from kernel state to user state, but is preempted by the kernel

Create

Stiff death

There are two unique processes in Unix. Process 0 is a predefined data structure created at system startup, and it is an exchange process. Process 0 produces process 1 at startup, and process 1 is called an initial process.

The creation process in Unix is implemented by calling fork () from the kernel system. When requested by fork, the system performs the following functions:

1. Assign an empty item in the process table for the new process.

two。 Assign a unique process identifier to the Forbidden City

3. Sound field A logical copy of the parent process context, excluding the shared memory area

4. Increase the counters for all files of the parent process

5. Make the child process ready

6. Returns the process number of the child process to the parent process and zero to the child process.

All operations are done in the kernel state of the parent process.

Thread

The concept of process proposed earlier includes two characteristics:

Resource ownership: a process includes a virtual address space where process images are stored.

Scheduling / execution: a process executes along an execution path that can pass through one or more programs. A process has an execution status and an assigned priority. It is an entity that can be scheduled and dispatched by the operating system.

To distinguish between these two characteristics, the dispatched unit becomes a thread or lightweight process, while the unit that owns the resource is called the process process or task.

Multithreading

The ability to support multiple concurrent execution paths within a single process.

The process is the minimum scheduling unit of the operating system, and the thread is the minimum scheduling unit of CPU.

Advantages of threads:

Thread creation is 10 times faster than process creation in Unix.

Terminating a thread is faster than a process

Thread switching is better than process block

The county town has improved the efficiency of communication between different executive programs. Inter-process communication requires the intervention of the kernel to share memory and files with threads in the process.

The characteristics of multithreading can only take effect on multiprocessor machines, and the single processor mainly simplifies the structure of programs that logically perform several different functions.

Classification of threads

Threads can be divided into two main categories:

1. User-level thread

two。 Kernel-level county seat

User-level thread

Thread management is done by the application, which the kernel is not aware of. Any application can use thread library pthread to design multithreaded programs. When executed, the program starts to run a process that is assigned to a kernel management from the county seat. The thread state of the program is limited by the kernel process state. As a result, its thread state also affects the process state.

Advantages:

1. All threads of the program are in the user address space without kernel state privileges and do not need to switch states.

two。 Custom scheduling algorithm

3. Cross-system, portable

Disadvantages:

1. Thread blocking causes process blocking

two。 Multicore performance cannot be used, and the kernel assigns only one process to one processor at a time

Kernel-level thread

All thread management is done by the kernel.

Advantages:

1. Simultaneously schedule threads to multi-core processors

two。 When one thread in a process is blocked, the kernel can schedule another thread in that process.

Disadvantages:

1. When passing control from one thread to another thread of the same process, a state switch of the kernel is required.

Multi-core and multi-thread

Examples of using threads in multiprocessor systems:

Foreground and background work: spreadsheet processing, a thread displays and reads input, and a thread executes commands to update the table.

Asynchronous processing:

Execution speed: when one thread Ithumb O is blocked, the other thread can continue to run.

Process and Thread Management of Linux

The process or task of Linux is represented by an task_struct data structure. Contains the following information:

Status

Dispatching information

Identifier

Interprocess communication

Link

Time and timer

File system

Address space

Processor specific context

The execution status of the process is as follows:

Running

Interruptible, blocking state, which waits for an event (such as the end of an Ihop O operation), a signal from an available resource, or another process

Uninterruptible, blocking state, this state waits for a hardware condition and does not accept any signal

Stop it

Stiff death

Copy the properties of the current process in Linux to create a new process. Use the clone command instead of the fork command to create a process. There are no separate data structures defined for threads, and when two processes share the same virtual memory, they can be treated as threads in the same process. The clone () call creates a separate stack space for each process, sharing the same memory space.

When the Linux kernel performs a process switch, it checks to see if the page directory address of the current process is the same as the process that will be scheduled, and if so, the context switch is simply jumping from one part of the code to the other.

Summary

Some operating systems distinguish between the concept of processes and threads, the former involving ownership of resources and the latter involving program execution.

User-level threads are unknown to the operating system, they are created and managed in the thread library in user space, and thread switching does not require state transition, which is very efficient, but only one user-level thread can execute a process at a time. If a thread is blocked, the whole process is blocked.

Kernel-level threads are maintained by the kernel, so that threads in the same process can execute concurrently on multiple processors without being blocked by one thread to block the whole process, but mode conversion is required when the thread is switched.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report