当前位置:网站首页>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 .
边栏推荐
- Unity发布WebGL播放声音的一种方法
- 腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
- Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?
- Market Research - current market situation and future development trend of aircraft audio control panel system
- Web side defense Guide
- U++ 原始内存 学习笔记
- Bridge emqx cloud data to AWS IOT through the public network
- Market Research - current market situation and future development trend of marine wet exhaust hose
- Hanoi Tower problem
- [shutter] shutter gesture interaction (small ball following the movement of fingers)
猜你喜欢
Lightgbm principle and its application in astronomical data
Radis:Linux上安装Redis(步骤)
[foreign journal] sleep and weight loss
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
[shutter] shutter gesture interaction (small ball following the movement of fingers)
C language, to achieve three chess games
Oracle PL / SQL programming
#include errors detected. Please update your includePath.
PMP项目整合管理
基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
随机推荐
Mathematical modeling -- graph and network models and methods (I)
Unity3d learning notes 4 - create mesh advanced interface
Simpleitk use - 4 Strange question
ArrayList analysis 2: pits in ITR, listiterator, and sublist
"Actbert" Baidu & Sydney University of technology proposed actbert to learn the global and local video text representation, which is effective in five video text tasks!
scrcpy这款软件解决了和同事分享手机屏幕的问题| 社区征文
Web side defense Guide
Necessary browser plug-ins for network security engineers
[shutter] shutter gesture interaction (small ball following the movement of fingers)
Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
钟薛高回应产品1小时不化:含固体成分 融化不能变成水
New feature of go1.18: introduce new netip Network Library
百度智能云-创建人脸识别应用
附加:【登录信息存储】与【登录状态校验】;(包括:总结了到目前为止,有关【登录信息存储】与【登录状态校验】的所有内容;)
【外刊】睡眠与减肥
[ODX studio edit PDX] -0.1- how to quickly view the differences in supported diagnostic information between variant variants (service, sub function...)
wait解决僵尸进程
Notes on key vocabulary in the English original of the biography of jobs (10) [chapter eight]
任务和特权级保护
Task and privilege level protection