Linux Process related concepts

Source: Internet
Author: User

1. Process invocation
2.CPU allocation
3. Process creation
4. Process scheduling
5. Memory allocation and recycling
6. Process Type
7. Process Status
8.IO process

I. Linux process and Job management
1. Process invocation:
Call: Calling someone else to implement a well-written function module
Can be based on {System Call/lib call} or Mixed call

System call: Usually occurs in the kernel
Library Call: Some may be a standalone module, some may be a two-time package for system calls

What does a process call mean?
CPU instruction: General instruction: Ring3//Any application can execute
Privileged directive: ring0//does not allow the program to be called arbitrarily, by the kernel calls, realizes the hardware platform management
Any program needs to run a privileged command, the OS encapsulates it as a call, it has to initiate a call to the kernel, which is executed by the kernel
System call in Ring3, initiated at RING0 Run, and then returned after completion of RING3
The process needs to run the RING0 command: A soft interrupt is initiated to initiate the system call
The kernel loads the code into the CPU, returns the execution result to the caller, and continues running subsequent code after the call.
The program needs to be paused: After system call continues to run, this is called soft interrupt

CPU instructions are divided into:
Privileged command: Ring 0//root Ring, memory address, memory control, set memory access to W/R
Privileged directives for ordinary users are not allowed to run privileged commands
Kernel-level and OS-level code to run privileged commands
ring1,ring2,//historical reasons, not used
User instruction: Ring3

When running user code: User mode/User space
Process initiates system call, requires soft interrupt: kernel mode/kernel space

For example mkdir/tmp/a: This requires an interrupt because the hardware is being manipulated
Role of the kernel: process management, fs,network functions
The CPU switches back and forth between the user instruction and the kernel instruction: mode switch
General: 70% code in user processes, other kernel processes best

2.CPU How to allocate resources//If the CPU has only one
Time slice cutting: times split
Process has a priority concept: use CPU in turn
1. If a process is hogging the CPU
Requires an arbitration mechanism: kernel (Process Management: Responsible for process scheduling)
2. Save Process Status
On a register on the CPU, there is a register on the CPU: the state of the current process is saved
Once you switch to the next command, these values will change
Process protection and recovery:
On-site information: stored by the kernel and stored in memory
Process information: Process number, memory number, status, CPU time allocation, etc.
Switchover is done by the kernel,
Fixed format for process information stored by the Linux kernel: task struct//task struct
Structure information, using linked list storage, easy to find
Linked list of task structs for multiple tasks: Task List
Process: A copy of a running program
Existence life cycle
The program is a static file
3. When an interrupt occurs, it must be taken over by the kernel

3. Process Creation
The organizational structure of each process is the same
The kernel creates the first process: Init
Init: the Messenger of God
When Init is created, it means that user space is also created.
Equivalent to the general agent:
He can create child processes, child processes create child processes
Parent-child Relationship
Process: Both created by its parent process//need to request to the kernel
Fork (), Clone ()//create child process [can be the same memory space], only when the child process needs to write data, the partition cow (copy on write) allocated another space
Process = instruction + data, when the need to write data, cow copy, to separate
The process terminates: frees up space, the parent process is responsible for
Parent process creates child process: In order for a child process to run a specific task, the child process is completed and needs to be destroyed

System calls:
Read (), write (), open ()
Parallel execution to thread run: very common//a parent program that creates its child processes, whose threads can run concurrently on other CPUs
A process can produce multiple threads, run in parallel//multi-core

4. Process scheduling
Priority: divided by fixed number://kernel after 2.6
0-99: Real-time priority//The higher the number, the greater the priority
100-139: Static priority//user can specify, the smaller the number, the higher the priority

Nice value: -20-+19//100-139, -20:100 +19:100//Adjust Priority
Linux kernel in order to quickly implement the process of scheduling: The system has been running the process of 140 queues
Shoot a team of the same priority//just scan the header of the queue

Big O: Algorithmic complexity
O (1), O (Logn), O (n), O (n^2), O (2^n)

Each pair of running queues has two teams://When the run queue is complete, and the expiration queue is swapped for identity
Run queue: True scan of
Expired queue: Queue that has been transferred

Data stored in the task struck:
threads, memory information, tty,fs,files, signals, etc.

5. Allocation and recovery of memory, creation, etc.
Memory Shard: 4K size, single page
Page frame: Pages box for storing page data
Storing the data stored in the page//page box becomes the page data
Memory cannot predict how much space a process needs to use: suppose
Kernel occupancy | Other processes use
Put other memory: cut into a fixed-size fragment page, assign these fragments to other processes
Size of memory footprint: not fixed, may grow later

After the process is started, the kernel is looking for a number of scattered free space, pieced together to allocate it to the process
There is a lot of memory: page frame consists of
And these page frame: all in a discontinuous or partial continuous way of composition

The page corresponds to a linear address and the page box corresponds to the physical address is the actual storage area

Tell the process to be continuous: through a middle layer, disguise
Every system thinks: There are only two people in the world, themselves and the kernel

Linear address space for processes: each process assumes that it has 3G (32bit) of memory available
Physical address space: the actual space occupied may be limited
There is a discrete correspondence between them, the virtual memory mechanism

LRU: Least Recently used algorithm
Linear address space mapped to memory space
Processes can only access: linear address space,
Mmu:memory Management unit//Memory Management Unit: Responsible for mapping between memory linear memory and physical memory
Once the memory is not used: The LRU algorithm, swapped into swap, turns the process back on again

The kernel holds a task_struck for each process: records the correspondence between the linear address space and the physical address space

Some programs have data that must be in memory: The resident memory set
The ability to swap out: virtual memory sets

Linux kernel: Preemptive multi-tasking//Process priority high preemption process with low priority
You can grab the CPU time slice that someone else is running.
Only at the corresponding point in time, can rob, can't process just on-line, began to rob the

6. Process Type:
Daemon: Daemon, a process initiated by the kernel at system boot time
Foreground process: User-enabled processes//and terminal-related
Note: You can also send the foreground-initiated process to the background to run in daemon mode.

7. Process Status:
Operating state: Running
Ready state: Readiness
Sleep state:
Interrupted sleep: interruptable
The CPU time slice is ready to run directly
Non-disruptive sleep: uninterruptable//For example, a process needs to wait for a large file to be loaded, even if the next CPU time slice is not satisfied with the running conditions
What does the process wait for? It is impossible for him to occupy the CPU, only let him get the CPU out and let the other processes run until the process satisfies the condition
This is called an IO process.
IO process: Data that a process needs to load, not in memory, has to request the kernel to load data from disk into memory
The process is not authorized to load the data into memory, only the kernel is requested, but the kernel is usually just loaded data, which is loaded into the memory in the kernel space
Stop state: Paused in memory, but not scheduled, unless manually initiated, stopped
Zombie State: Zombie, after a child process is created and the task is completed, wait for the parent process to clean up
The parent process hangs, but the child process still exists

8.IO Process:
1. The data is first loaded into the kernel memory from the disk
2. Copying a copy into the process memory
Classification of processes:
Cpu-bound//cpu Intensive
Io-bound//io Intensive

Ipc:inter preocess communication: interprocess communication
Process is not aware of the existence of other processes
On the same host:
Signal//common means of communication
Shm:shared Memory
On different hosts:
Rpc:remote procecure Call//Remote procedure invocation
Socket: socket-based communication
A process listens in one place and can accept messages sent by others
One end just sends data to the socket, the kernel automatically transmits the data to the other end, and the other

This article is from the "Dark Horse vacated" blog, please be sure to keep this source

Linux Process related concepts

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.