当前位置:网站首页>Process creation fork (), demise wait()
Process creation fork (), demise wait()
2022-06-12 19:38:00 【Lee Neo】
1、 Process identifier pid
type pid_t;; It can hold more than 30000 people at most ,16 Long long
ps command
ps axf
getpid();
getppid();
2、 The creation of processes
fork();
Pay attention to understanding keywords :duplicating, Means copy 、 clone 、 Two complete copies of the same code , The position of execution is the same ;
fork The difference between parent and child processes after :
- fork The return value of is different ;
- pid Different ,ppid Different ;
- Pending signals and file locks do not inherit ;
- Resource utilization cleared ;
init process :1 Number , Is the ancestor of all processes
- The scheduler's scheduling policy determines which process runs first ; You can't guess which parent-child process runs first ;
- fork The buffer needs to be flushed before
Automatically refresh : added \n When you are outputting standard output , Because of the row cache , It is equivalent to automatically flushing the buffer ;
But when you output to /tmp/out when , Will be printed twice begin. Because fork With buffer begin It is also copied to the child process ;
Manually refresh :fork Before to add fflush(NULL); With or without /n, Standard output or not , Will only print once Begin;

Programming topics :
- use 200 The subprocess determines whether twohundred numbers are prime numbers ;
Note that the subprocess ends when it finishes its work (exit、return);
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define LEFT 30000000
#define RIGHT 30000200
int main()
{
int i, j, mark;
for (i = LEFT; i <= RIGHT; i++)
{
mark = 1;
for (j = 2; j < i / 2; j++)
{
if(i%j == 0)
{
mark = 0;
break;
}
}
if(mark)
printf("%d is a primer\n",i);
exit(0); Be sure to end the child process ;
}
exit(0);
}
- Who creates who recycles ;
The child process can be regarded as a resource created by the parent process , If the parent process does not end ( Nor recycle resources ), Child processes can become zombie processes ;
The child process that the parent process ends will become an orphan process , from init() management ;
The main harm of zombie process is Occupy pid resources ;
vfork();

- fork() Of ” Copy while writing “ technology :
- Who writes who copies ;
- When read-only, the parent and child processes share physical memory ;
3. Processes die and resources are freed
wait();
waitpid ();
Allocation algorithm :
- Block method ;
- Cross allocation algorithm ; The general crossover algorithm is better than the block method ;
- pool
4.exec function
5、 User and group permissions
6. Observation class : Interpreter files
7、 system()
8、 Process accounting
9、 Process time
10、
边栏推荐
- First build green, then build city
- Original publishing practice of pipeline in Jenkins docking with CMDB interface to obtain host list
- easycode一键生成插件自定义模板
- Market scale forecast and future competitive trend outlook report of China's plastic and cosmetic industry 2022-2028
- Cookie & session & kaptcha verification code
- Hardware test - why not use grounding clip for ripple test
- VC Hacon Joint Programming genimage3extern writeimage
- Original introduction to Jenkins' configuration options
- Super heavy! Apache Hudi multimode index optimizes queries up to 30 times
- Shell arrays and functions
猜你喜欢

存储体系概述

exec函数、shell的实现

解释器文件

基於分布式數據庫本身的定時備份方法

Demand and business model analysis-3-design
![[SQL] MySQL query statement execution sequence analysis](/img/e0/6c55b798b5debfc780fb51498455ab.jpg)
[SQL] MySQL query statement execution sequence analysis

Pyinstaller packaging tutorial packaging resource files

基于微信电子书阅读小程序毕业设计毕设作品(7)中期检查报告

Demand and business model innovation - demand 4- overview of demand acquisition

In 2021, the global revenue of chlorinated polyvinyl chloride (CPVC) was about $1809.9 million, and it is expected to reach $3691.5 million in 2028
随机推荐
IO流基础知识详解--文件及IO流原理
[generation confrontation network learning III] reading notes of Bigan paper and its principle understanding
Demand and business model analysis-2-business model types
Méthode de sauvegarde programmée basée sur la base de données distribuée elle - même
How does Eldon's ring of the law get lune quickly? Introduction to the fastest and safest method for obtaining lune
Market scale forecast and future competitive trend outlook report of China's plastic and cosmetic industry 2022-2028
Demand and business model analysis -6- five topics
PHP converts total seconds to hours, minutes and seconds
RT-Thread 模拟器 simulator 搭建 LVGL 的开发调试环境
China's asset management market demand and future competitive trends outlook report 2022-2028
"As a service", the future has come, starting from the present | new mode of it consumption, FOD billing on demand
Hardware test - why not use grounding clip for ripple test
编程工具下载地址
Typescript decorator is basically used
The component style set by uniapp takes effect in H5 and app, but does not take effect in wechat applet. The problem is solved
Download and configuration of nuitka packaging tutorial
Basic structure of arithmetic unit
In 2021, the global fire pump drive power revenue is about $381million, and it is expected to reach $489.3 million in 2028
模块八作业
Report on market demand trends and future strategic planning recommendations of the global and Chinese smart financial solutions industry 2022-2028