CS计算机代考程序代写 computer architecture file system FIT1047 Tutorial 7 – Sample Solution Topics

FIT1047 Tutorial 7 – Sample Solution Topics
• Operating Systems • Processes
Instructions
The tasks are supposed to be done in groups of two or three students.
For some of the questions, you may have to refer to the free online textbook at http:
//www.ostep.org/, or do some internet research.
Task 1: Operating Systems
• Discuss the functions & goals of an Operating System?
Functions and Goal of Operating System
-Efficient use of a Computer System & User convenience
– Ease of Use
Operating system manages main memory, processor, device and file system manipulation. It also responsible for protection and security of the system, control over system performance, job accounting, error detection aids, and coordination between other software and users. Operating system also supports multiple execution mode.
An Operating System can not provide both because user convenience often conflicts with efficient use of a computer system. Efficient use is important when a computer is shared by several users while user convenience is important in personal computers.
User convenience has higher priority than efficient use of a Computer System in Windows Operating System while efficient use of a Computer System has higher priority than user convenience in Unix Operating System.
In regards to a modern, multitasking, multiuser, preemptive OS on a modern hardware platform, Provides consistent and common services to the user software applications, it handles:
CPU; memory (virtual and paging); hardware interrupts; DMA; timers; Input/Output port mapping; processes/threads; inter process communication; HAL (device drivers), all sorts of, e.g. file system, hardware, etc; process scheduling and resource access security.
But most importantly it creates an environment (heavily hardware assisted) for a process to run as if it was the only process out there running, philosophical culmination of the OS, is to protect itself and user processes from each other also free user application from the burden to manage all of the above.

• Explain the concept of Abstraction in Operating Systems OSs?
The most important concept in Computer architecture is the layer of abstraction, Hide complexity from users & Provide clean, well-defined interface to functionality.
So the O.S basically provides abstraction from the hardware, So the main mechanism for that is called virtualization so, Virtualization means that we provide the illusion of having access to some resource and hardware even though we do not have exclusive access, for Example: The O.S provides virtual form of each physical resource to each process, say you write a program for modern O.S, you could program as thought you have access to the entire CPU for your program self. You don’t have to worry that other process are running at the same time, you could write a program that you have access to a large block of memory to yourself(program). Exclusive Access at all the hardware through the device drivers interrupt handlers to access any hardware. Etc..
Processes: Processes are the abstraction of the CPU an system calls. Basically a container for a reference to all the info needed to run a program.
Address Space: is the O.S abstraction of memory and are pieces of addresses that corresponds to the memory space allocated to the program use.
Files: are the abstraction for the disk, providing program a way to interact and store info on the disk. Files are typically grouped into a directory structure.
Task 2: Processes
1. What is the difference between a process and a program?
A program is the code stored on disk or in memory. A process is an instance of that program while it is running (a program “in execution”). The same program can be running as several processes at the same time – on different computers, or even on the same computer.
2. A context switch happens when execution switches between a process and the operating system (e.g. to handle an interrupt). What does a context switch have to do?
It has to save the current process state so that it can be restored when control is passed back to the process. The process state consists of the contents of all registers that can be accessed through the code (this includes the PC, but doesn’t include special-purpose internal registers such as MBR or MAR in MARIE). A context switch also sets the CPU mode, switching from user mode to kernel mode or back (depending on the direction of the switch).
3. Explain the different states that a process can be in.
A process can be in one of three states: ready, running, and blocked. In the ready state, a process ready to run, but it’s not currently running on the CPU. After loading code from a file into memory and setting up all the necessary bookkeeping in the OS, the ready state is the first state a process is placed in.
A process in the running state is currently being executed on the CPU. A process goes from ready to running when the operating system schedules the process and switches to it. There can only be one process in the running state at any point in time (or one per CPU in a multi-CPU system).

A process is in the blocked state when it is currently waiting for a system call to return. E.g. if a process requests some data to be read from a file, it makes the corresponding system call, and since file I/O is slow, the OS may decide to schedule other ready processes in the meantime. As soon as the data has been read successfully, the process is moved from blocked to the ready state, and at some point will be scheduled to become running again.
Task 3: Protection
An important concept in Operating Systems is Protection, meaning that one malicious
or buggy process cannot bring another process or even the entire system down.
• Explainthedifferencebetweenusermodeandkernelmode
In kernel mode, code is completely unrestricted, it can contain any instruction, and it has full access to the hardware. In user mode, code cannot access the hardware directly, because the CPU will refuse to execute the corresponding instructions. A lot of operating system code needs to run in kernel mode. Application programs run in user mode.
• Whyaresystemcallsnecessarywhenapplicationprogramsruninusermode?Since applications cannot execute CPU instructions to access the hardware, they need some other mechanism to e.g. open a file or read from the keyboard. A system call is a call from an application program (in user mode) into the operating system (running in kernel mode).
• List and explain the two variants of process switching
The two variants are Cooperative and Preemptive process switching, The basic difference between preemptive and non-preemptive scheduling lies in their name itself. That is a Preemptive scheduling can be preempted; the processes can be scheduled. In Non- preemptive scheduling, the processes can not be scheduled.
Cooperative (non-preemptive):
Switch into kernel when user code makes a system call, or when a hardware interrupt happens. In cooperative scheduling, the processes cannot be scheduled.
The operating system never initiates a context switch from a running process to another process
Preemptive:
Wait for a timer interrupt
Preemptive scheduling can be preempted; the processes can be scheduled.
The operating system will initiates a context switch from a running process to another process

• Find a list of system calls in the Linux operating system. How many are there? Which system call numbers would you have to use to get the current time, open a file, create a new directory, and exit the process?
A list can be found e.g. at http://syscalls.kernelgrok.com.
System call
time open mkdir exit
Description
get current time open a file
create a directory exit the process
number
13 5 39 1
Task 4: Examining running processes
Explore the processes currently running on your computer. On Windows, start the Task Manager. On Mac OS, start the Activity Monitor. On many Linux systems, you can run a program called System Monitor, or run the top command line tool.
1. How many processes are currently running?
2. How many processors (or cores) does your computer have?
3. Find out how much of the processor(s) is currently in use, and by which process. Try a few things (e.g. playing a video in a web browser) to see how CPU usage goes up and down.
4. Can you find out how much time is spent in user mode vs. kernel mode?