资源简介
山东大学 软件学院 2017-2018学年春季
操作系统实验一
独立实验答案

代码片段和文件信息
/*
Author: KMDJ
PublishedOn: CSDN
Filename: exp1.c
*/
#include “exp1.h“
int main(int argc char *argv[]){
int i;
int pid1;
int pid2;
int status1;
int status2;
char *arg1[] = {“/bin/ls“ “-a“ NULL};
char *arg2[] = {“/bin/ps“ “-l“ NULL};
signal(SIGINT(sighandler_t)sigcat);
pid1=fork();
if(pid1<0){
printf(“Create Process failed!\n“);
exit(EXIT_FAILURE);
}
if(pid1==0){
printf(“I am Child process %d\nMy father is %d\nI will execute command ‘ls -a‘ later\n“ getpid() getppid());
printf(“\n“);
pause();
printf(“%d child will Running: \n“ getpid());
for(i=0; arg1[i]!=NULL; i++) printf(“%s“ arg1[i]);
printf(“\n“);
status1=execve(arg1[0] arg1 NULL);
}
else{
sleep(1);
pid2=fork();
if(pid2==0){
printf(“I am Child process %d\nMy father is %d\nI will execute command ‘ps -l‘ later\n“ getpid() getppid());
printf(“\n“);
pause();
printf(“%d child will Running: \n“ getpid());
for(i=0; arg2[i]!=NULL; i++) printf(“%s“ arg2[i]);
printf(“\n“);
printf(“\n“);
status2=execve(arg2[0] arg2 NULL);
}
else{
sleep(1);
printf(“\nI am Parent process %d\n“ getpid());
if(kill(pid2SIGINT)>=0)
printf(“\n%d wakeup %d child.\n“ getpid() pid2);
printf(“%d wait for child done.\n“ getpid());
waitpid(pid2 &status1 0);
printf(“%d child process done.\n“ pid2);
if(kill(pid1SIGINT)>=0)
printf(“\n%d wakeup %d child.\n“ getpid() pid1);
printf(“%d wait for child done.\n“ getpid());
waitpid(pid1 &status1 0);
printf(“%d child process done.\n“ pid1);
printf(“\nParent process done\n“);
}
}
return EXIT_SUCCESS;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14984 2018-05-26 10:15 exp1
文件 1984 2018-07-14 17:24 exp1.c
文件 247 2018-06-05 13:02 exp1.h
文件 7416 2018-05-26 10:15 exp1.o
文件 182 2018-05-26 09:55 Makefile
相关资源
- 电梯模拟程序C/C 算法实现
- linux系统的二级文件系统(QT实现了简
- VS开发进阶源码---烟花特效的生日祝福
- 路由分组转发仿真系统的设计与实现
- 漏洞扫描工具openvas的源码
- Bonjour SDK for Windows
- 《深入理解计算机系统》随书代码
- 炫彩界面库帮助文档chm-v2.5.0
- 嵌入式华清远见培训 ARM代码内部资料
- 2/3FEC编码
- 精简版黑白棋demo-Qt
- 线性表的基本操作vs2017
- 基于Qt5的俄罗斯方块游戏
- WS2812库 arduino测试通过
- VC全景图拼接算法源码毕业设计+论文
- 超市信息管理系统课程设计.docx
- zlib动态链接库x86&64;
- openssl1.1.1源码
- vc做的小游戏 —— 彩色泡泡
- linux+QT下基于RTP协议的实时视频传输客
- cmake-3.17.2-win64-x64.zip
- C用Easyx图形库编写贪吃蛇.zip
- 图像细化算法
- 北斗模块GPS定位显示
- 西电-面向对象课件褚华老师所著
- gsl-2.6.7z
- 《编译原理第二版》完整版
- vim配置成强大的IDE
- K66_逐飞.zip
- mingw-w64压缩包
评论
共有 条评论