• No results found

file descriptor “fd” in the above operations and why the

N/A
N/A
Protected

Academic year: 2020

Share "file descriptor “fd” in the above operations and why the"

Copied!
7
0
0

Loading.... (view fulltext now)

Full text

(1)

COMP SCI 3SH3: Operating System Concepts

;

Term 2 (Winter 2005)

Test 1 January 31, 2005; Time: 50 Minutes ; Seven Questions

Instructor: Dr. Kamran Sartipi

Question 1 (General): [5 marks]

What are the three main purposes of an operating system? [1 correct: 2marks; 2 correct: 4 marks; 3 correct: 5 marks]

1. To provide an environment for computer user to execute programs on computer hardware in a convenient and efficient manner.

2. To allocate the separate resources of the computer as needed to solve the problem given. The allocation process should be fair and efficient as possible.

3. As a control program it serves two major functions: i) supervision of the

execution of user programs to prevent errors and improper user of the computer, and ii) management of the operation and control of I/O devices.

Question 2 (file system): [20 marks]

Below the sketch of the Unix facilities for file system calls is shown consisting of: two tables; table entries; and primitive operations that work on these tables.

Tables:

- SysT: System wide file-table

- PerT: Per-process file-table

Fields in a Table-entry corresponding to a file:

- SysT: file name; owner name; type; location in disk; size; time/date; file open count.

- PerT: access control; read/write pointer.

-Some Primitive operations:

- RD(fileName) # Read the directory information for a file from # the disk, and put them in a Table above.

- WD(fileName) # Write back the information of a file from Tables # to the disk.

- SF(Table, fileName) # Search a Table for file name and return the Table # entry number for that file (if file exists in Table).

- DT(Table, entryNum) # Delete the Table entry by giving its entry number.

-Answer the following questions:

A. Fill the fields of the Tables with file attributes: file name; owner name; type; location in disk; size; access control; time/date; read/write pointer; file open count

(2)

B. Explain where is a file descriptor “fd” in the above operations and why the operating systems use file descriptors to handle file operations. [5 marks]

The entryNum above is a file descriptor “fd”.

The operating systems use “fd” to handle file operations read or write after the file has been opened. A “fd” is a means to prevent the operating systems from

frequently performing time consuming search operations to locate a file name (or a directory name) within a directory listing.

C. Use the above primitive operations, and also modify Table fields above for a file to perform the following file system calls. [4 marks each: total 20 marks, ie, 10 marks bonus]

i. create-file(fileName) # Note: create-file does not open the file

1. In an empty entry in the table SysT (an empty FCB) create the information for a new file by setting the fields: fileName = “fileName”; ownerName = “name of the file

owner”; type = “extension of the file, e.g., .txt, .doc, .ppt”; a location on disk allocated to the file data; size = 0; current time/date; file open count = 0.

2. Write back the information for FCB to the disk using the primitive operation WD(fileName).

ii. open-file(fileName, Read-and-Write)

1. Using the primitive operation SF(SysT, fileName) search table SysT to find the file “fileName”; increment its “file open count”; put a pointer to this entry into an empty entry in the table PerT; set the Read-and-Write access control and the read/write pointer into the PerT entry; and return the entry number of PerT as the file descriptor “fd”.

2. If the file does not exist in table SysT then use the primitive operation RD(fileName) to read its FCB from the disk and put it in an empty slot of table SysT; initialize the “file open count” to 1, and follow the operations mentioned above in order to return the file descriptor “fd”.

iii. write-file(fd, Buffer, 100)

Use “fd” to access the PerT table entry and then get the SysT entry number to access the FCB of the corresponding file; get the pointer to the location of the file in disk from FCB; get the read/write pointer from PerT table; group 100 words from the Buffer into disk block data (based on the current read/write pointer) and write the prepared blocks of data into the corresponding disk blocks and update read/write pointer.

iv. close-file(fd)

(3)

entry decrease the “file open count” and obtain the name of the file (fileName), if the count becomes zero then delete the SysT table entry as well using the operation DT(SysT, entryNumber); and write the FCB from the SysT into the hard disk using WD(fileName).

v. delete-file(fileName)

1. The file is already closed, hence the PerT entry is already deleted. Search in the SysT table using SF(SysT, fileName) to obtain the corresponding FCB of the file.

Delete FCB in the SysT entry as explained above.

Question 3 (General): [ 10 marks]

In two lines for each type of operating system below identify the following properties: i. Main objective

ii. Advantages or constraints [2 marks each]

Operating systems: [2 marks each] NOTE: the provided answers are more detailed than are needed for full mark.

a. Batch

i) Jobs with similar needs are batched together and run through the computer as a group by an operator or automatic job sequencer. Performance is increased by attempting to keep CPU and I/O devices busy at all times through buffering, off-line operation, spooling, and multiprogramming.

ii) Pros: Batch is good for executing large jobs that need little interaction; it can be submitted and picked up later. Cons: non-interactive

b. Time sharing:

i) These systems use CPU scheduling and multiprogramming to provide economical interactive use of a system. The CPU switches rapidly from one user to another. Each program reads its inputs from terminal and prints it immediately to the screen.

ii) Pros: Responsive, Multiprogramming, Multiuser. Cons: overhead for context switching

c. Real time

i) Often used in a dedicated application, this system reads information from sensors and must respond within a fixed amount of time to ensure correct performance.

ii) Pros: accurate timing, working for embedded systems. Cons: lack of sophisticated modern operating system features.

(4)

i) These systems distribute computation among several physical processors. The processors do not share memory or a clock. Instead, each processor has its own local memory. They communicate with each other through various communication lines, such as a high-speed bus or telephone line.

ii) Pros: increased throughput, Cons: unpredictable delay time.

e. Handheld

i) These are small computer systems that are mainly intended for simple task processing: calendar, pocket calculator, browsing pictures/messages, and network connectivity.

ii) Pros: easy to use and carry. Cons: limited screen, memory, and battery life.

Question 4 (Interrupt): [15 marks]

In the figure below the interrupt handling mechanism to service an I/O device (disk drive) is shown. Answer the following questions:

A. Briefly explain what is a trap [4 marks]

See page 28: a trap (or an exception) is a software generated interrupt caused either by an error (for example, division by zero or invalid memory access) or by a specific request from a user program that an operating system service will be performed.

B. How does a hard disk drive store the blocks of data. [3 marks]

The blocks of data are stored in the sectors of the hard disk cylinders, where a hard disk cylinder constitutes a group of 10 equally size disk tracks in different platters.

C. For each numbered arrow in the figure, separately explain what operations will be performed in order to transfer a block of data from the disk drive into a memory buffer. Hint: interrupt vector is used here. [8 marks]

1. The CPU programs the disk controller registers to read a block of data from a particular cylinder and sector of the disk drive; the CPU then continues its operations.

2. After a block of data is read from the disk drive, the disk controller raises its interrupt signal to let the CPU know about that. This signal is transferred to an interrupt controller device which encodes its input signals into binary numbers.

3. The interrupt controller issues an interrupt signal to the CPU on behalf of the disk controller; the CPU acknowledges the interrupt by issuing an Interrupt Acknowledge signal (INTA).

(5)

Question 5 (Process creation): [10 marks]

A.

Name five items in the Process Control Block (PCB).

[4 marks]

1) Process state 2) Process id 3) Program counter 4) CPU registers

5) CPU scheduling information 6) Memory-management information 7) Accounting information

8) I/O status information

B. Briefly explain the steps that the operating system takes in order to perform the fork() system call including the blocking and signaling the processes. What would be the value of PID in: PID = fork() after the fork is performed? [6 marks]

For a comprehensive explanation refer to the pages 104 – 106 of the text book. i) When a parent process invokes the “fork()” system call, the operating

system performs a context-switch and dispatches proper operating system processes to take care of the child process creation.

ii) The parent process is blocked and is put at the end of the ready queue to be scheduled later;

iii) The whole contents of the parent’s PCB is copied into an empty entry (slot) of the PCB table, the new PCB will be the PCB of the newly created child process and the index number of the new PCB would become the child’s PID;

(6)

v) After being dispatched, both parent and child processes with resume their executions from the fork() system call; the parent process will receive the PID of its child and the child will receive 0 as the PID which is an

indication to this process that it is the child process;

vi) The parent process will then block itself by executing “wait()” system call and will wait in a queue until all its child (children) processes are

terminated, at which time the parent process is signaled to be waken up and synchronize itself with its child (children).

Question 6 (DMA): [ 10 marks]

With reference to the figure below, circle the correct answer(s) about Direct Memory Access operations: [5 marks each]

A. The CPU programs the I/O controller (IOC), DMA controller

(DMAC), and memory, such that when the device produces a byte of data the DMAC interrupts the CPU to transfer data to memory. B. DMAC will take the control of the system bus for any data transfer. C. Once the IOC receives a block of data from device, it interrupts the

CPU to assign DMAC to transfer that block of data to memory.

D. The CPU programs IOC and DMAC; IOC notifies DMAC to transfer a block of data to memory; and finally DMAC interrupts the CPU to access the block of data in memory.

E. DMAC transfers data from IOC in bytes or blocks of bytes by fully controlling the CPU.

Question 7 (IPC): [10 marks]

(7)

A. P1 sends an RPC request (for service X) to the local matchmaker as its client stub and the matchmaker contacts the matchmaker at the server side to find the port address of the service X.

B. P1 invokes an RPC service X from OS and OS after obtaining the port address of service X from the matchmaker, it sends an RPC requests to the corresponding port that provides service X.

C. P1 invokes RPC service X from local OS and OS sends the request to

matchmaker at server side. The matchmaker then looks up and finds its local service X, perform service X and returns the result to the client side OS where the result is returned to the client process P1.

References

Related documents

 HCC is developing in 85% in cirrhosis hepatis Chronic liver damage Hepatocita regeneration Cirrhosis Genetic changes

Selling someone else’s intellectual property is flogging stolen goods.. Which is not just illegal, it’s the wrong thing

The summary resource report prepared by North Atlantic is based on a 43-101 Compliant Resource Report prepared by M. Holter, Consulting Professional Engineer,

In Figure 24, we present a concept design for a speech room consisting of a reflective front wall and ceiling above the presenter to amplify sound, even when the presenter turns

○ If BP elevated, think primary aldosteronism, Cushing’s, renal artery stenosis, ○ If BP normal, think hypomagnesemia, severe hypoK, Bartter’s, NaHCO3,

The SWARMs ontology uses a core ontology to interrelate a set of domain-specific ontologies, including the mission and planning, the robotic vehicle, the communication and

Herbivory competes with fire for the available grass fuels and may prevent fires or reduce  fire  intensity  in  some  areas,  as  fuels  are  eaten  before 

Flow-through electrodes have been shown to increase power density and fuel utilization compared to planar (flow-over) electrodes, 31 be- cause the fuel is able to contact a