1 / 15
文档名称:

操作系统实验报告.doc

格式:doc   大小:82KB   页数:15页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

操作系统实验报告.doc

上传人:fyyouxi23 2022/4/23 文件大小:82 KB

下载得到文件列表

操作系统实验报告.doc

文档介绍

文档介绍:-
. z.
操作系统实验报告
**:
**:
ait(NULL);printf("a\n");e*it(0);}
}
}
〔2〕进程控制
#include<>
#include<>
int main()
{
int pid1, pid2;
pid1=fork();
if (pid1<0){ printf("Fork 1 failed!!");}
if (pid1==0){ printf("This is child b\n");e*it(0);}
-
. z.
if (pid1>0){ wait(NULL);
pid2 = fork();
if (pid2<0) { printf("Fork 2 failed!!"); }
if (pid2==0) { printf("This is child c\n");
e*it(0);}
if (pid2>0) { wait(NULL);
printf("This is father a\n");
e*it(0);}
}
}
〔3〕进程的管道通信
#include<>
#include<>
#include<sys/>
#include<>
int main()
{
int pid1, pid2; int pfd[2];
char *msg1="Child 1 is sending a message!";
char *msg2="Child 2 is sending a message!";
char buf[256]; int r,w;
if(pipe(pfd)<0){ printf("pipe create error!\n"); e*it(1);}
pid1 = fork();
if (pid1<0){ printf("Fork 1 failed!!");}
if (pid1==0){ close(pfd[0]); //write
sleep(3);
if(w=write(pfd[1],msg1,strlen(msg1))<0){ printf("wirte error!\n");
e*it(1);}
else { printf("child 1 send msg to pipe!\n"); }
e*it(0);
}
if(pid1>0)
{
wait(NULL);pid2 = fork();
if(pid2<0){ printf("Fork 2 failed!!");}
if(pid2>0)
{ close(pfd[1]); //read
sleep(3);
-
. z.
if(r=read(pfd[0],buf,256)<0){ printf("read error!\n");e*it(1);}
else { printf("parent read from pipe: %s\n",buf); }
wait(NULL); close(pfd[1]); //read
sleep(3);
if(r=read(pfd[0],buf,256)<0){ printf("read error!\n");e*it(1);}
else { printf("parent read from pipe: %s\n",buf);}
}
if(pid2==0)