联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Web作业Web作业

日期:2025-02-10 11:16

CSCI-UA.0202-001 Operating Systems

Homework 1

Due: Wednesday, September 18, 2024 

These problems should be done on your own. We’re not going to be grading them strictly (we’ll mainly look at whether you attempted them). But they will be reinforcing knowledge and skills, so you should totally work through them carefully.

Please save your answers (and references) as a PDF file and upload it to Brightspace.

Question 1

Alice is writing a simple program to practice the use of pointers. She uses the function add() to calculate the sum of two integers. Instead of returning the value, the function returns a pointer to the result.

#include <stdio .h>

 

int *add(int a , int b) {

int c = a + b;

int *d = &c;

return d;

}

 

int main() {

int *result = add(1 , 2);

 

printf("result = %d\n" , *result);

printf("result = %d\n" , *result);

}

Surprisingly, Alice notices that if she prints the result for the second time, the result is wrong! So she turns to you for help.

(1)  Can you explain what’s happening here?

(2) Alice insists that add() should return a pointer. Can you propose a way to fix it?

Question 2

Bob is playing with the UNIX/Linux shell, and he is confused about the following commands …

1. echo 'echo cat'  | cat

2. echo 'echo cat' > cat

3. echo 'echo cat' >> cat

4. echo `echo cat` | cat

5. cat < cat

Can you explain to Bob what each command does? What would happen if Bob executes these commands in order?

Question 3

What is the difference between kernel and user mode? Explain how having two distinct modes aids in designing an operating system.

Question 4

What is a trap instruction? Explain its use in operating systems.

Question 5

Instructions related to accessing I/O devices are typically privileged instructions, that  is, they can be executed in kernel mode but not in user mode. Give a reason why these instructions are privileged.

 

 



版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp