Ex1
来源:互联网 发布:登陆阿里云服务器 编辑:程序博客网 时间:2024/05/19 22:43
Please show all work on a separate sheet attached to this sheet.
(50 points)
1. What are the two main functions of an operating system?
What is multiprogramming?
(5 points)
Ans: 1) An operating system must provide the users with an extended
(i.e., virtual) machine, and it must manage the I/O devices and
other system resources.
2) Multiprogramming is the rapid switching of the CPU between multiple
processes in memory. It is commonly used to keep the CPU busy while one
or more processes are doing I/O.
2. Refer to the section 1.3 and pick up one type of operating
systems of your interest. List at least two examples of your
pick and list their main features.
(10 points)
Ans: Operating systems for palmtop computers and embedded systems are picked.
1) Palm OS
Developed by PalmSource, Inc.
Features:
o Built-in Personal Information Manager (PIM) programs
o Work with a PC
o One-tap ease of use
o Wired and wireless communication
2) Pocket PC
Developed by Microsoft Corporation
Features:
o Built-in Personal Information Manager (PIM) programs
o Can run popular Microsoft applications
o Wired and wireless communication
3. A typical use of the fork system call is to allow a server to
create a slave to service an incoming request. However, if
the time required to process the request is very short, it is
common to have the server process the request without taking
the time to fork off a child process. For example, suppose that
it takes x msec to create a process using fork and y msec to
service the request. (10 points)
(a) If x is much smaller than y, should a slave be created to
service the request? Explain.
(b) If y is much smaller than x, should a slave be created to
service the request? Explain.
Ans: (a) If x is much smaller than y, a slave should be created to
service the request because the time required to process
the request is long and the overhead of forking a new
process would be negligible.
(b) If y is much smaller than x, a slave should not be created
to service the request because the time required to process
the request is very short and the overhead of forking a
new process would be substantial.
4. For each of the following system calls, give a condition that
causes it to fail: fork, exec, and unlink.
(5 points)
Ans: Fork can fail if there are no free slots left in the process table (and
possibly if there is no memory or swap space left).
Exec can fail if the file name given does not exist or is not a valid
executable file.
Unlink can fail if the file to be unlinked does not exist or the calling
process does not have the authority to unlink it.
5. In Fig 2-10, a multithreaded Web sever is shown. If the only
way to read from a file is the normal blocking read system
call, do you think user-level thread or kernel-level threads
are being used for the Web server? Why?
(10 points)
Ans: A worker thread will block when it has to read a Web page from the
disk. If user-level threads are being used, this action will block
the entire process, destroying the value of multithreading. Thus
it is better that kernel threads are used to permit some threads
to block without affecting the others.
6. Consider the following section of code:
main()
{
int pid;
pid = fork();
if (pid > 0) {
printf("In child./n");
exit(0);
}
printf("In parent./n");
}
Assume that the fork() system call is successful. What will be
printed when the code is executed? If there is an error, how can
it be fixed?
What happens if the fork() system call is not successful.
(10 points)
Ans: 1) The following will be printed:
In child.
In parent.
The code can be fixed as follows:
main()
{
int pid;
pid = fork();
if (pid = 0) {
printf("In child./n");
exit(0);
}
printf("In parent./n");
}
2) If the fork() system call is not successful, the return value of the
fork() system call is -1. The fixed code will only show
In parent.
- Ex1
- ex1
- ex1
- SICP ex1-11 ex1-12 ex1-14
- [Haskell] ex1
- python ex1
- ex1.py
- SICP ex1-20 ex1-22
- SICP ex1-23 ex1-25
- SICP ex1-30 ex1-31
- SICP ex1-17 ex-18 ex1-19
- 正则表达式ex1
- SICP ex1.11
- Start cpp learnning ex1
- coursera Machine Learning ex1
- Stanford Machine Learning ex1
- 斯坦福 机器学习 ex1
- ex1 Gradient Descent
- JDBC笔记(一)
- 一键GHOST 硬盘版 安装运行
- 内核模式
- Alexa排名作弊方法分析
- 《C#图解教程》读书笔记第7章——类和继承
- Ex1
- ComboBox的使用总结
- 第5章 Eclipse中CVS的使用
- [转]嵌入式系统硬件初始化
- 搞笑
- 开博涂鸦
- 随机分配体育比赛胸牌号
- 幽默技巧
- ARM初始化过程详解