C program for gallons that converts in cubic feet.

Q29.  Assuming that there are 7.481 gallons in a cubic foot, write a C program that asks the user to enter the number of gallons, and then displays the equivalent in cubic feet.

Ans.

#include<stdio.h>

#include<conio.h>   //for clrscr()

void main()

{

float gallon, cbft;

clrscr();  //for clear screen

printf(“\n Enter the number of gallons: “);

Read More …

File Types

Q1. What are the types of file?

Ans.When we design a file system—indeed, an entire operating system—we always consider whether the operating system should recognize and support file types. If an operating system recognizes the type of a file, it can then operate on the file in reasonable ways.

 

A common technique for implementing file types is to include the type as part of the file name. The name is split into two parts—a name and an extension,usually separated by a period character (Figure 10.2). In this way, the user andthe operating system can tell from the name alone what the type of a file is.

 

File name examples include resume.doc, Scrver.java, and

ReaderThread.c

File Type Usual Extension Function
executable exe, com, bin or none ready-to-run machine language program.
object obj, o compiled, machine language not linked.
source code c,cc,java,pas,asm,a source code in various languages.
batch bat, sh commands to the command interpreter.
text txt, doc textual data, documents
word processor wp, tex, rtf, doc various word-processor formats.
library lib, a, so, dll libraries of routines for programmers.
print or view ps, pdf, jpg ASCII or binary file in a format for printing or viewing.
archieve arc, zip, tar related files grouped into one file, sometimes compressed, for archiving or storage.
multimedia mpeg, mov, rm, mps, avi binary file containing audio or A/V information.

Figure: Common File Type

File Operations

Q1. What all operations are performed on a file?

Ans. A file is an abstract data type.

Following are the operations performed by on a file:

 

  1. Creating a file

Two steps are necessary to create a file. First, space in thefile system must be found for the file. Second, an entry for the new file must be made in the directory.

 

  1. Writing a file

To write a file, we make a system call specifying both thename of the file and the information to be written to the file. Given the name of the file, the system searches the directory to find the file’s location. The system must keep a write pointer to the location in the file where the next write is to take place. The write pointer must be updated whenever a write occurs.

 

  1. Reading a file

To read from a file, we use a system call that specifies thename of the file and where (in memory) the next block of the file shouldbe put. Again, the directory is searched for the associated entry, and thesystem needs to keep a read pointer to the location in the file where the next read is to take place. Once the read has taken place, the read pointer is updated.

 

  1. Repositioning within a file

The directory is searched for the appropriateentry, and the current-file-position pointer is repositioned to a given value. Repositioning within a file need not involve any actual I/O. This file operation is also known as a file seek.

 

  1. Deleting a file

To delete a file, we search the directory for the named file.Having found the associated directory entry, we release all file space, so that it can be reused by other files, and erase the directory entry.

 

  1. Truncating a file

The user may want to erase the contents of a file butkeep its attributes. Rather than forcing the user to delete the file and then recreate it, this function allows all attributes to remain unchanged—except for file length—but lets the tile be reset to length zero and its file space released.

File Attributes

Q1. What are File Attributes?

Ans.A file’s attributes vary from one operating system to another but typically consist of these:

  1. Name

The symbolic file name is the only information kept in human readableform,.

  1. Identifier

This unique tag, usually a number, identifies the file within thefile system; it is the non-human-readable name for the file.

  1. Type

This information is needed for systems that support different types of files.

  1. Location

This information is a pointer to a device and to the location ofthe file on that device.

  1. Size

The current size of the file (in bytes, words, or blocks) and possiblythe maximum allowed size are included in this attribute.

  1. Protection

Access-control information determines who can do reading, writing, executing, and so on.

  1. Time, date, and user identification

This information may be kept forcreation, last modification, and last use. These data can be useful for protection, security, and usage monitoring.

File Concept

Q1. Explain File Concept.

Ans. Computers can store information on various storage media, such as magnetic disks, magnetic tapes, and optical disks. So that the computer system will be convenient to use, the operating system provides a uniform logical view of information storage. The operating system abstracts from the physical properties of its storage devices to define a logical storage unit, the file. Files are mapped by the operating system onto physical devices. These storage devices are usually nonvolatile, so the contents are persistent through power failures and system reboots.

I/O Interlock

Q1. Explain I/O Interlock.

Ans.When demand paging is used, we sometimes need to allow some of the pages to be locked in memory. One such situation occurs when I/O is done to or from user (virtual) memory. I/O is often implemented by a separate I/O processor.

 

For example, a controller for a USB storage device is generally given the number of bytes to transfer and a memory address for the buffer. When the transfer is complete, the CPU is interrupted.

TLB Reach

Q1. Explain TLB Reach.

Ans.The TLB reach refers to the amount of memory accessible from the TLB and is simply the number of entries multiplied by the page size.

 

TLB Reach = Number of entries X Page Size

 

Ideally, the working set for a process is stored in the TLB. If not, the process will spend a considerable amount of time resolving memory references in the page table rather than the TLB. If we double the number of entries in the TLB, we double the TLB reach.

 

Translation Look Aside Buffer (TLB)

Q1. Explain Translation Look Aside Buffer (TLB).

Ans.Translation look aside buffer is a special, small, fast-lookup hardware cache. The TLB is associative, high-speed memory. Each entry in the TLB consists of two parts:

A key (or tag) and

A value.

When the associative memory is presented with an item, the item is compared with all keys simultaneously. If the item is found, the corresponding value filed is returned. The search is fast, the hardware, however, is expensive. Typically, the number of entries in a TLB is small, often numbering between 64 and 1,024.

The TLB is used with page tables in the following way. The TLB contains only a few of the page table entries. When a logical address is generated by the CPU, its page number is found, its frame number is immediately available and is used to access memory. The whole task may takes less than 10 percent longer than it would if an unmapped memory reference were used.

If the page number is not in the TLB (known as a TLB miss), a memory reference to the page table must be made. When the frame number is obtained, we can use it to access memory. In addition, we add the page number and frame number to the TLB, so that they will be found quickly on the next reference. If the TLB is already full of entries, the operating system must select one for replacement.

Figure: Paging hardware with TLB

Purpose of Using Cache Memory

Q1. Explain the purpose of using Cache Memory.

Ans. Information is normally kept in some storage system such as main memory. As it is used, it is copied into a faster storage system—the cache—on a temporary basis. When we need a particular piece of information, we first check whether it is in the cache. If it is, we use the information directly from the cache; if it is not, we use the information from the source, putting a copy in the cache under the assumption that we will need it again soon.

 

In addition, internal programmable registers, such as index registers, provide a high-speed cache for main memory.