【操作系统】Linux之进程管理二

第1关:进程等待

if(wait(&status) != -1)

{

if(WIFEXITED(status))

status = WEXITSTATUS(status);

else

status = -1;

}

else

{

status = -1;

}

第2关:进程创建操作-exec函数族

void execlProcess()

{

pid_t pid = vfork();

if(pid == -1)

{

printf("创建子进程失败(%s)\n", strerror(errno));

return -1;

}

else if(pid == 0)

{

//子进程

/********** BEGIN **********/

if(execle("touch","touch","testDir",NULL)<0)

{

exit(-1);

}

/********** END **********/

}

else

{

//父进程

/********** BEGIN **********/

printf("Parent Process");

/********** END **********/

}

}

第3关:进程创建操作-system

int test=system("mkdir testDir");

if(test==1)

{

return test;

}

第4关:实现一个简单的命令解析器

int i=0;

while(i<commandNum)

{

system(cmdi);

i++;

}

相关推荐
三言老师4 小时前
秘诀-如何远程SSN访问家里的八台电脑(frp 实操方案)
linux·运维·ssh
hold?fish:palm5 小时前
24 回文链表
数据结构·c++·链表
举手6 小时前
Dispatcher模块剖析
linux·c++
何事误红尘6 小时前
全志A40i学习笔记():开发资料、启用串口
学习
for_ever_love__6 小时前
python基础语法学习: 异常的传递性
开发语言·python·学习
PC2005-cloud7 小时前
DeepSeek Harness 创建 skill 指南:结构、安装、使用
笔记·学习
YM52e7 小时前
分页查询的基石:ArkTS 为鸿蒙商品列表设计 LIMIT/OFFSET 的表
android·学习·华为·harmonyos
allforgood7 小时前
运行容器
linux
math_hongfan7 小时前
主从嵌套层次分明:ArkUI 订单卡片内嵌明细的鸿蒙界面
学习·华为·harmonyos
Light_It8 小时前
Linux 内核参数 pci-stub.ids=
linux·kernel