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

}

相关推荐
哈基咪怎么可能是AI8 小时前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行1 天前
Linux和window共享文件夹
linux
木心月转码ing1 天前
WSL+Cpp开发环境配置
linux
崔小汤呀2 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应2 天前
vi编辑器使用
linux·后端·操作系统
何中应2 天前
Linux进程无法被kill
linux·后端·操作系统
何中应2 天前
rm-rf /命令操作介绍
linux·后端·操作系统
何中应2 天前
Linux常用命令
linux·操作系统
葛立国2 天前
从 / 和 /dev 说起:Linux 文件系统与挂载点一文理清
linux
西岸行者3 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习