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

}

相关推荐
崔小汤呀2 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应2 天前
vi编辑器使用
linux·后端·操作系统
何中应2 天前
Linux进程无法被kill
linux·后端·操作系统
何中应2 天前
rm-rf /命令操作介绍
linux·后端·操作系统
何中应2 天前
Linux常用命令
linux·操作系统
葛立国2 天前
从 / 和 /dev 说起:Linux 文件系统与挂载点一文理清
linux
西岸行者2 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
琢磨先生David2 天前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
哇哈哈20212 天前
信号量和信号
linux·c++
不是二师兄的八戒3 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器