当前位置:网站首页>Wait to solve the zombie process
Wait to solve the zombie process
2022-07-02 22:46:00 【Htht111】
C0301—2022.0315
Process general statement
Call... In the parent process wait function , See the effect . The whole parent process does three things : Print twice 、 One call wait function .
One 、 The subprocess makes an endless loop .
int pid = 0;
int status = 0;// state
int res = 0;//wait Return value
pid = fork();
if (pid == 0)
{
cout << " Enter the subprocess logic pid=" << getpid() << endl;
for (int i = 0; i >-1; i++)
{
cout << " Subprocesses for i=" << i << endl;
sleep(2);// Prevent printing too fast
}
}
else if (pid>0)
{
cout << " Enter the parent process logic pid=" << getpid() << endl;
res = wait(&status);
cout << "wait after The parent process "<< endl;
}
because VS return Breaking points can't end , So use linux Kernel compilation runs .
Generate — Rebuild the solution
To Ubuntu Find the folder where the project is located , Right click Open at terminal
Compile run discovery
(1) The subprocess has been in an endless loop
(2) The parent process only takes the first step , And in a wakeable state of sleep .
wait Wait for the subprocess to finish before returning the value , The subprocess in this example is an endless loop .
Two 、 The subprocess loop can end , Observe the parent process call wait What happens after the function
int pid = 0;
int status = 0;// state
int res = 0;//wait Return value
pid = fork();
if (pid == 0)
{
cout << " Enter the subprocess logic pid=" << getpid() << endl;
for (int i = 0; i <10; i++)
{
cout << " Subprocesses for i=" << i << endl;
sleep(2);
}
}
else if (pid>0)
{
cout << " Enter the parent process logic pid=" << getpid() << endl;
res = wait(&status);
cout << "wait after The parent process res="<<res<< endl;
}
After compiling and running , In circulation
After the subprocess cycle ends , You can see , The parent process printed the call wait Statement after function . After the subprocess cycle ends ,wait Function returns the ID, Then print the following statement .
Thus we can see that ,wait The function blocks , After the subprocess runs , Then return to the child process ID, Then the following operations .
Can solve , The child process ends before the parent process , Problems causing the zombie process .
边栏推荐
- NC24325 [USACO 2012 Mar S]Flowerpot
- Task and privilege level protection
- Unity3d learning notes 4 - create mesh advanced interface
- Promise optimized callback hell
- SimpleITK使用——3. 常见操作
- Oracle cursor
- Notes on key vocabulary of the original English book biography of jobs (IX) [chapter seven]
- Commodity information management system (C language document version)
- [QT] QT multithreading development - four methods to realize multithreading design
- U++ learning notes - relaxation
猜你喜欢
Promise optimized callback hell
540. Single element in ordered array
Phpcms realizes the direct Alipay payment function of orders
SimpleITK使用——3. 常见操作
Pointer and string
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
PMP项目整合管理
wait解决僵尸进程
UE4 game architecture learning notes
Micro service gateway selection, please accept my knees!
随机推荐
Socket套接字C/S端流程
【ODX Studio编辑PDX】-0.1-如何快速查看各Variant变体间的支持的诊断信息差异(服务,Sub-Function...)
Web side defense Guide
[shutter] shutter application theme (themedata | dynamic modification theme)
UE4 游戏架构 学习笔记
Dynamic memory allocation (malloc calloc realloc free)
《乔布斯传》英文原著重点词汇笔记(十一)【 chapter nine】
原生js添加样式的方法
杰理之直接触摸样机的顶针反应不正常【篇】
U++ 原始内存 学习笔记
Regular expression (2)
Film and television excerpts
Les trois principaux points de douleur traités par servicemesh
杰理之修改不需要长按开机功能【篇】
Servicemesh mainly solves three pain points
服务器响应状态码
Market Research - current market situation and future development trend of aircraft front wheel steering system
Attack and defense world PWN question: Echo
Market Research - current market situation and future development trend of intravenous injection (IV) bottles
U++ 学习笔记 ----松弛