【操作系统】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(cmd[i]);

i++;

}

相关推荐
zylyehuo几秒前
在 Ubuntu 下进行磁盘分卷
linux
li星野4 分钟前
DeepSeek-V3介绍
学习
sdm07042717 分钟前
Linux-库制作与原理
linux·c++·操作系统
MimCyan29 分钟前
prompt越狱手册(个人笔记记录-2026.03.31)
笔记·prompt
Heartache boy31 分钟前
野火STM32_HAL库版课程笔记-TIM通道捕获应用之超声波测距
笔记·stm32·单片机
地下核武34 分钟前
Ubuntu 26.04 “星际之门”(Luminous) 发布全解析
linux·运维·ubuntu
sorel_ferris36 分钟前
Ubuntu 22.04 NVIDIA 驱动问题修复报告
linux·ubuntu
暂未成功人士!36 分钟前
在windows电脑上的vscode使用sftp将项目文件与嵌入式平台(Ubuntu)同步的方法
linux·运维·vscode·ubuntu·ssh
正经人_x40 分钟前
学习日记36:TokenSeg
学习
VelinX42 分钟前
【个人学习||spring boot】
spring boot·后端·学习