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

}

相关推荐
0xDevNull10 小时前
Linux切换JDK版本详细教程
linux
进击的丸子10 小时前
虹软人脸服务器版SDK(Linux/ARM Pro)多线程调用及性能优化
linux·数据库·后端
齐生110 小时前
iOS 知识点 - IAP 是怎样的?
笔记
tingshuo29171 天前
D006 【模板】并查集
笔记
Johny_Zhao2 天前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
tingshuo29172 天前
S001 【模板】从前缀函数到KMP应用 字符串匹配 字符串周期
笔记
chlk1233 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑3 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件3 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号4 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移