操作系统实验报告
- 格式:doc
- 大小:64.00 KB
- 文档页数:10
课程设计实验报告
课程名称:操作系统原理
姓名:
学号:
2012年06月18日
青岛工学院信息工程系实验报告
实验一进程创建
1.实验目的
了解在linux系统c语言下的编译环境。
熟练地进行程序的编译,执行。
2.实验环境配置
Linux系统下
3.实验内容(源代码)
#include
int main()
{
int p1,p2;
while((p1=fork())==-1);
if(p1==0)
{
putchar('b');
return 0;
}
else
{
putchar('a');
while((p2=fork())==-1);
if(p2==0)
{
putchar('c');
return 0;
}
}
}
4.实验结果分析
运行结果可能是:baca、baac、aacb等
实验二管道通信1.实验目的
了解什么是管道
熟悉Unix/Linux操作系统支持管道通信
2.实验内容(源代码)
#include
#include
#include
#include
int pid1,pid2;
main()
{
int fd[3];
char OutPipe[100],InPipe[100];
pipe(fd);
while((pid1=fork())==-1);
if(pid1==0)
{
wait(0);
printf("p1\n");
lockf(fd[0],1,0);
printf("p1:");
read(fd[0],InPipe,50);
printf("%s\n",InPipe);
lockf(fd[0],0,0);
exit(0);
}
else
{
while((pid2=fork())==-1);
if(pid2==0)
{
wait(0);
printf("p2\n");
lockf(fd[0],1,0);
printf("p2:");
read(fd[0],InPipe,50);
printf("%s\n",InPipe);
lockf(fd[0],0,0);
exit(0);
}
else
{
printf("parent\n");
sprintf(OutPipe,"child 1 process is sending a message!");
write(fd[1],OutPipe,50);
sleep(1);
sprintf(OutPipe,"Child 2 process is sending a message!");
sleep(2);
write(fd[1],OutPipe,50);
sleep(1);
exit(0);
}
}
return 0;
}
3.实验结果分析
可能的执行结果:
p1
p2
parent
p2:child 1 process is sending a message!
p1:Child 2 process is sending a message!
管道运行结果
parent
p1
p1:child 1 process is sending a message!
p2
p2:Child 2 process is sending a message!
p1
p2
parent
p1:child 1 process is sending a message!
p2:Child 2 process is sending a message!
parent
p2
p2:child 1 process is sending a message! p1
p1:Child 2 process is sending a message!
p1
parent
p1:child 1 process is sending a message! p2
p2:Child 2 process is sending a message!
实验三软中断通信
1.实验目的
理解掌握软中断的概念和技术
掌握进程之间基于软中断的通信技术
2.实验内容(源代码)
#include
#include
#include
#include
#include
#include
void waiting(),stop();
int wait_mark;
main()
{
int p1,p2;
int stdout;
while ((p1=fork())==-1);
if (p1>0)
{
while((p2=fork())==-1);
if(p2>0) {
printf("parent\n");
wait_mark=1;
signal(SIGINT,stop);
waiting ();
kill(p1,16);
kill(p2,17);
wait(0);
wait(0);
printf("parent process is killed !\n");
exit(0);
}
else
{
signal(SIGINT,stop);
printf("p2\n");
wait_mark=1;