当前位置:网站首页>IO进程线程->进程->day4
IO进程线程->进程->day4
2022-08-02 07:39:00 【鲸叫我照顾海QAQ】
目录
练习
1.创建一个孤儿进程
2.创建一个僵尸进程
一、孤儿进程
就是只有子进程还在执行,父进程已经结束,父进程号为1。
1.1 孤儿函数
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
pid_t pid=fork();
if(0 == pid)
{
while(1)
{
printf("孤儿进程\n");
sleep(1);
}
}
else if(pid > 0)
{
sleep(2);
}else
{
perror("fork");
}
return 0;
}
1.2 执行结果
ps -ajx 查看Linux进程的信息
二、僵尸进程
就是父进程还在执行,子进程已经结束,但是父进程没有给该进程收尸。
2.1 僵尸函数
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
pid_t pid=fork();
if(0 == pid)
{
sleep(2);
}
else if(pid > 0)
{
while(1)
{
printf("僵尸进程\n");
sleep(1);
}
}else
{
perror("fork");
}
return 0;
}
2.2 执行结果
ps -ajx 查看Linux进程的信息
边栏推荐
- MySQL优化之慢日志查询
- 解决IDEA安装安装插件慢问题
- PanGu-Coder:函数级的代码生成模型
- sql创建表格 如图 运行完提示invalid table name 是什么原因
- postgres 水平分表,自动创建分区,按时间分表
- gdalinfo: error while loading shared libraries: libgdal.so.30: cannot open shared object file: No su
- Inverter insulation detection detection function and software implementation
- WebRTC系列-SDP之编码信息收集
- 18、优化网站性能
- MySQL压缩包方式安装,傻瓜式教学
猜你喜欢
Aided by training and learning by battle | The new version of the Offensive and Defense World Platform is officially launched!
Install Metasploitable2 on VMware
MySQL - Index Optimization and Query Optimization
flutter 自己写一个组件
Buried development process
HCIP第二天
论文理解:“Cross-Scale Residual Network: A GeneralFramework for Image Super-Resolution,Denoising, and “
Inverter insulation detection detection function and software implementation
2022-7-31 12点 程序爱生活 恒指底背离中,有1-2周反弹希望
解决IDEA安装安装插件慢问题
随机推荐
Data reveal that the average cost is as high as $4.35 million in 2022, a record!
基于PyTorch的flappy bird游戏
How to export multiple query results at once in SQL server 2014?
JVM垃圾回收与性能调优方式
Inverter insulation detection detection function and software implementation
WebGPU 导入[2] - 核心概念与重要机制解读
2022-7-31 12点 程序爱生活 恒指底背离中,有1-2周反弹希望
牛客2022 暑期多校4 D Jobs (Easy Version)(递推优化策略)
HCIP第七天
设置工作模式与环境(中):建造二级引导器
uni.navigateBack 中的坑
Fatal error compiling: 无效的目标发行版: 11
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
Comprehensive experiment of MPLS and BGP
59: Chapter 5: Develop admin management services: 12: MongoDB usage scenarios; (non-core data, non-core data with a relatively large amount of data, small private files such as face photos;)
17、生成长图,并上传至服务器
PanGu-Coder: A function-level code generation model
MySQL之创建表的基本操作
Compact格式下MySQL的数据如何存储到磁盘
Kind of weird!Access the destination URL, the host can container but not