【操作系统】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++;

}

相关推荐
worxfr几秒前
Linux 磁盘空间排查与清理指南
linux·运维·chrome
Kurisu5753 分钟前
最终幻想VII重制版修改器下载2026最新版
linux·游戏
chushiyunen3 分钟前
elasticsearch笔记
笔记·elasticsearch·jenkins
Cloud_Shy6183 分钟前
Linux 用户管理知识与应用实践(一:用户及用户组基础知识)
linux·运维·服务器·centos·云计算
dusk_star4 分钟前
go语言--笔记--接口
java·笔记·golang
小陈phd4 分钟前
多模态大模型学习笔记(四十二)——从像素到语义的精准问询——视觉问答(VQA)
笔记·学习
Jempo M5 分钟前
GDB 与 LLDB 逆向调试的艺术:从原理到实战,Linux 与 Windows 调试全解析
linux·运维·服务器
比昨天多敲两行11 分钟前
Linux进程间通信-共享内存
linux·运维·服务器
AbandonForce11 分钟前
Linux权限深入解读
linux·运维·服务器
哎呦,帅小伙哦13 分钟前
Nanomsg usock 模块:Socket 选项与错误码介绍
linux·中间件·nanomsg