当前位置:网站首页>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、
边栏推荐
- 94. analyze the content in the web page
- Download and configuration of nuitka packaging tutorial
- What is data driven
- Wangxuegang room+paging3
- In 2021, the global fire pump drive power revenue is about $381million, and it is expected to reach $489.3 million in 2028
- Mode of most elements (map, sort, random, Boyer Moore voting method)
- JDBC接口总结
- China's asset management market demand and future competitive trends outlook report 2022-2028
- VC hacon joint programming genimage3extern writeimage
- Promise to solve hell function calls can be used infinitely
猜你喜欢

运算器的基本结构

Demand and business model innovation-5-process

Hardware test - why not use grounding clip for ripple test

DACOM G150 dual-mode earphones make sound for love and protect the healthy growth of children's hearing

Wechat e-book reading applet graduation design works (1) development outline

基于微信电子书阅读小程序毕业设计毕设作品(2)小程序功能

基于微信电子书阅读小程序毕业设计毕设作品(3)后台功能

Demand and business model innovation - demand 3- demand engineering process

Implementation of VGA protocol based on FPGA

基于微信电子书阅读小程序毕业设计毕设作品(4)开题报告
随机推荐
Demand and business model analysis-3-design
Wangxuegang room+paging3
基于微信电子书阅读小程序毕业设计毕设作品(8)毕业设计论文模板
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
EASYCODE one click plug-in custom template
What are meta-inf and WEB-INF respectively?
Wincc7.5 SP1 method for adjusting picture size to display resolution
Implementation of VGA protocol based on FPGA
Demand and business model analysis-1-business model canvas
在 Traefik Proxy 2.5 中使用/开发私有插件(Traefik 官方博客)
vc hacon 聯合編程 GenImage3Extern WriteImage
5g R17 standard is frozen. What does it say?
基于微信电子书阅读小程序毕业设计毕设作品(6)开题答辩PPT
3GPP RAN第一次F2F会议,都干了些啥?
The 14th five year development plan and investment prospect analysis report of China's oil and gas pipeline engineering construction 2022-2027
[observation] Huawei's next generation data center "adds momentum" to Guangxi's low-carbon and high-quality development
Business opportunities with an annual increase of 3billion - non cage eggs or a new blue ocean for export to ASEAN
设备管理-借还模块1
What are the third-party software testing organizations in Shanghai that share knowledge about software validation testing?