当前位置:网站首页>Basic knowledge of process (orphan, zombie process)
Basic knowledge of process (orphan, zombie process)
2022-07-07 11:06:00 【Exy-】
Catalog
The von Neumann system :
Computer hardware architecture - Five hardware units Input , Output , Arithmetic unit , Memory , All devices of the controller work around memory ( What memory does in all devices is to buffer data
operating system :
Management software - Manage the software and hardware resources on the computer , Make the computer easier to use
management : describe + organization
system call : The operating system provides an interface for users to access system kernel resources
Library function : The encapsulation of the system call interface by the bosses for the functions of typical scenarios
The relationship between library functions and system call interfaces : The calling relationship between superior and subordinate .
Process concept :
From the user's point of view, a process is a running program , But from the perspective of the operating system , The process is pcb- Process control block , stay linux Next is task_struct Structure , Is the operating system's description of the program running , Complete the management of program operation through these descriptions .
Description information in the process : identifier -PID, Memory pointer , Program counter , Context data ,IO Information , Process status ,...
cpu Time sharing mechanism : The operating system makes every program run in cpu Only for a short period of time ( Time slice ), Switch operation .
Process status
linux Process state classification under :
- R(running) Running state : It refers to the process that is running and can run after getting the time slice
- S(sleeping) Interruptible sleep state , It means that the current block can be awakened by interruption
- D(disk sleep) Non interruptible sleep state , It means that the current block cannot be awakened by interruption , Wait for yourself to wake up when the conditions are met
- T(stopped) Stop state The current process stops running , Do nothing
- Z(zombie) Deadpan , A process in which resources are not completely released after the program exits
Here we focus on orphan process and zombie process
Process creation
pid_t fork(void), Returns the of the child process to the parent process pid; Return... To the child process 0; Failure to return -1
View process information instructions ps -ef perhaps ps -aux, Usually with | grep To use .
Zombie process
Concept : Simply put, the child process exits before the parent process , The parent process does not recycle the child process , Release the resources of the child process , At this point, the sub process becomes a zombie process
harm : Memory leak , Take up a lot of resources
How to avoid ?
have access to wait To wait for
Orphan process
Concept : Contrary to the zombie process , It is because the parent process exits before the child process , Cause the child process to be 1 Number (init) Process takeover , At this time, the child process is an orphan process .
Daemon - Elvish process : It's a special orphan process , Running in the background , Break away from the terminal .( Use setsid();)
Create an orphan process
#include<stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
pid_t id = fork();
if(id < 0){
perror("fork");
return 1;
}
else if(id == 0){//child
printf("I am child, pid : %d\n", getpid());
sleep(5);
}else{//parent
printf("I am parent, pid: %d\n", getpid());
sleep(10);
exit(0);
}
return 0;
}
environment variable (path)
The so-called environment variable is the variable that saves the running environment of the program
Related instructions :
env | View all environment variables |
set | View all variables in the environment |
echo | Print the data of a specified variable |
export | Used to declare environment variables |
unset | Delete variables |
Important environmental variables :
PATH : The default search path of the system
HOME : Specify the user's home working directory ( That is, the user logs in to Linux Time in system , The default directory )
SHELL : At present Shell, Its value is usually /bin/bash
characteristic : It has transitivity between processes , Inherit , For example, the child process has the environment variables of the parent process
Each program will receive a table of environment variables , It's in main The third argument to the function , Is an array of string pointers
The benefits of environmental variables : The system running environment configuration is simpler and more flexible , You can pass parameter information to the process by setting environment variables .
Global variables : The configuration file needs to be modified , Variables are permanent
local variable : Use export Command statement is enough , Variable is closing shell Time lapse .
Program address space
The operating system virtualizes an independent and complete virtual address space for each process , Each process can access its own independent and continuous virtual address, but the actual data storage can be stored in different locations of physical memory after address mapping , This realizes the discrete storage of data in physical memory , Improved memory utilization
Program address space , Essentially, the operating system passes... For the process mm_struct Describe the virtual address space , Let each process access an independent and continuous virtual address , After mapping , Realize discrete storage in physical memory .
So why prohibit direct access to physical memory ?
The code data of the process are all continuous memory addresses , Direct access to physical space will cause a waste of memory .
Direct access to memory will lead to insecurity due to the lack of memory access control .
Typical way of memory management of operating system :
Paging management ; Segmented management ; Section management
Page replacement algorithm
One of the difficulties in the implementation of page virtual memory is the design of page replacement algorithm , When you call a new page into memory , If all the physical pages in memory have been allocated , It is necessary to discard a page according to a certain strategy , Release the physical page it occupies . For example, there is a first in first out Scheduling Algorithm (FIFO), The most recently unused scheduling algorithm (LRU). Best permutation algorithm (OPT).
Missing pages interruption
The page to be accessed by the operating system is not in main memory , You need to call it into main memory before accessing .
边栏推荐
- 长列表性能优化方案 memo
- Openinstall and Hupu have reached a cooperation to mine the data value of sports culture industry
- 中级网络工程师是什么?主要是考什么,有什么用?
- Deconstruction and assignment of variables
- POJ1821 Fence 题解报告
- Static semantic check of clang tidy in cicd
- 请问申购新股哪个证券公司开户是最好最安全的
- 香橙派OrangePi 4 LTS开发板通过Mini PCIE连接SATA硬盘的操作方法
- 简单易修改的弹框组件
- Galaxy Kirin desktop operating system installation postgresql13 (source code installation)
猜你喜欢
随机推荐
Use load_ decathlon_ Datalist (Monai) fast loading JSON data
高级软考(网络规划设计师)该如何备考?
uniCloud
How to play video on unityui
Get pictures through opencv, change channels and save them
How much review time does it usually take to take the intermediate soft exam?
The difference between monotonicity constraint and anti monotonicity constraint
[untitled]
Is the gold content of intermediate e-commerce division in the soft exam high?
Unity downloads files through the server address
Poj1821 fence problem solving Report
Monai version has been updated to 0.9. See what new functions it has
Records on the use of easyflash v3.3
shardingsphere分库分表示例(逻辑表,真实表,绑定表,广播表,单表)
單調性約束與反單調性約束的區別 monotonicity and anti-monotonicity constraint
2022年7月10日“五心公益”活动通知+报名入口(二维码)
Deep understanding of Apache Hudi asynchronous indexing mechanism
1323: [example 6.5] activity selection
Find the greatest common divisor and the least common multiple (C language)
What is an intermediate network engineer? What is the main test and what is the use?