UNIX is an Operating system for all computers and was written in C programming language.

features • • • • • • • programmers environment simple user interface simple utilities that can be combined to perform powerful functions hierarchical file system simple interface to devices consistent with file format multi-user, multi-process system architecture independent and transparent to the user.

Architecture 1. UNIX is equipped with a number of user services and interfaces. 2. User programs can invoke Operating system services either directly or through library programs. 3. The system call interface is the boundary with user and allows higher-level software to gain access to specific Kernel functions. 4. Operating system contains primitive routines that interact directly with the hardware. 5. between Kernel and hardware interface, the system is divided into: (i)Process control subsystem’ which is responsible for memory management, the scheduling, dispatching of processes, synchronization and IPC of processes. (ii) “File System’ that exchanges data between memory and external devices either as a stream of characters or in blocks. 6. It is designed to run on a single processor and lacks the ability to protect its data structures from concurrent access by multiple processors. 7. Its kernel is not very versatile, supporting a single type of file system, process scheduling policy and executable file format. 8. Traditional UNIX is not designed to be extensible and has few facilities for code reuse. How the UNIX file system works? Every item in a UNIX file system can de defined as belonging to one of four possible types: Ordinary files Ordinary files can contain text, data, or program information. An ordinary file cannot contain another file, or directory. An ordinary file can be thought of as a onedimensional array of bytes. Directories In a previous section, we described directories as containers that can hold files, and other directories. A directory is actually implemented as a file that has one line for

each item contained within the directory. Each line in a directory file contains only the name of the item, and a numerical reference to the location of the item. The reference is called an i-number, and is an index to a table known as the i-list. The ilist is a complete list of all the storage space available to the file system. Special files Special files represent input/output (i/o) devices, like a tty (terminal), a disk drive, or a printer. Because UNIX treats such devices as files, a degree of compatibility can be achieved between device i/o, and ordinary file i/o, allowing for the more efficient use of software. Special files can be either character special files, that deal with streams of characters, or block special files, that operate on larger blocks of data. Typical block sizes are 512 bytes, 1024 bytes, and 2048 bytes. Links A link is a pointer to another file. Remember that a directory is nothing more than a list of the names and i-numbers of files. A directory entry can be a hard link, in which the i-number points directly to another file. A hard link to a file is indistinguishable from the file itself. When a hard link is made, then the i-numbers of two different directory file entries point to the same inode. For that reason, hard links cannot span across file systems. A soft link (or symbolic link) provides an indirect pointer to a file. A soft link is implemented as a directory file entry containing a pathname. Soft links are distinguishable from files, and can span across file systems. Not all versions of UNIX support soft links. evThe I-List When we speak of a UNIX file system, we are actually referring to an area of physical memory represented by a single i-list. A UNIX machine may be connected to several file systems, each with its own i-list. One of those i-lists points to a special storage area, known as the root file system. The root file system contains the files for the operating system itself, and must be available at all times. Other file systems are removable. Removable file systems can be attached, or mounted, to the root file system. Typically, an empty directory is created on the root file system as a mount point, and a removable file system is attached there. When you issue a cd command to access the files and directories of a mounted removable file system, your file operations will be controlled through the i-list of the removable file system. The purpose of the i-list is to provide the operating system with a map into the memory of some physical storage device. The map is continually being revised, as the files are created and removed, and as they shrink and grow in size. Thus, the mechanism of mapping must be very flexible to accomodate drastic changes in the number and size of files. The i-list is stored in a known location, on the same memory storage device that it maps. Each entry in an i-list is called an i-node. An i-node is a complex structure that provides the necessary flexibility to track the changing file system. The i-nodes contain the information necessary to get information from the storage device, which typically communicates in fixed-size disk blocks. An i-node contains 10 direct pointers, which point to disk blocks on the storage device. In addition, each i-node also contains one indirect pointer, one double indirect pointer, and one triple indirect

pointer. The indirect pointer points to a block of direct pointers. The double indirect pointer points to a block of indirect pointers, and the triple indirect pointer points to a block of double indirect pointers. By structuring the pointers in a geometric fashion, a single i-node can represent a very large file. It now makes a little more sense to view a UNIX directory as a list of i-numbers, each i-number referencing a specific i-node on a specific i-list. The operating system traces its way through a file path by following the i-nodes until it reaches the direct pointers that contain the actual location of the file on the storage dice. The file system table Each file system that is mounted on a UNIX machine is accessed through its own block special file. The information on each of the block special files is kept in a system database called the file system table, and is usually located in /etc/fstab. It includes information about the name of the device, the directory name under which it will be mounted, and the read and write privileges for the device. It is possible to mount a file system as "read-only," to prevent users from changing anything. File system quotas Although not originally part of the UNIX filesystem, quotas quickly became a widelyused tool. Quotas allow the system administrator to place limits on the amount of space the users can allocate. Quotas usually place restrictions on the amount of space, and the number of files, that a user can take. The limit can be a soft limit, where only a warning is generated, or a hard limit, where no further operations that create files will be allowed.

Virtual Memory "Virtual memory is memory that appears to be allocated to application programs. The operating system uses a portion of the hard disk as virtual memory, and swaps data between the hard disk and physical memory. Virtual memory enables multitasking. If your computer needs to run several programs simultaneously, and the memory that all these programs require exceeds the amount of physical memory available, the operating system allocates virtual memory to meet the total memory requirements of each program, and then manages the available physical memory to meet the actual memory requirements at each point in time. Therefore, the amount of virtual memory that is allocated can be much greater than the amount of physical memory that is installed in the computer.".Paging occurs when an active process requires more memory than what is accessible in physical memory. Portions of the process are moved to disk so the physical memory can be used for something else. Swapping is done by the kernel. When memory space is running low the kernel looks for a process that isn't likely to run in the near future. That process is written entirely to disk, and the newly-freed memory is reassigned to another process or job. Process Management

UNIX system makes use of simple but powerful process facility that is visible to the user. UNIX follows the model in which most of the O.S executes within the environment of a user process. There are two modes user mode and kernel modes UNIX uses two categories of process 1. System processes 2. User processes System process run in kernel mode and executes 0.5. Code to perform administrative and housekeeping functions such as allocation of memory and process swapping. User process run in the user mode to execute user programs and utilizes and in the kernel mode to execute instructions belong to the kernel. User process enter kernel mode by issuing a system call, when n exception (fault) is generated or when an interrupt occurs.

1. 2. 3. 4. 5. 6. 7. 8.

User running- executing in User mode. Kernel running- executing in kernel mode. Ready to run in memory- ready to run as soon as the kernel schedules it. Asleep in memory- unable to execute until an event occurs, process is in main memory Ready to run swapped- process is ready to run, but the swapper must swap the process into main memory before the kernel can schedule it to execute. Sleeping swapped- the process is awaiting an event and has been swapped to secondary storage Preempted- process is returning from kernel to user mode, but the kernel preempt, it and does a process switch to schedule another process Created- process is newly created and not ready to run

Zombie- process no longer exist but it leaves a record for its parent process to collect. Working of fork command: Process creation in UNIX is made by means of the kernel system call fork 0. When a process issues a fork request for process creation, the Operating system performs the following functions: (i) It allocates a slot in the process table for the new process. (ii) It assigns a unique process ID to the child process. (iii) It makes a copy of the process image of the parent, with the exception of any shared memory. (iv) It increments counters for any files owned by the parent, to reflect that an additional process now also owns those files. (v) It assigns the child process to a ready to run state. (vi) It returns the ID number of the child to the parent process, and a 0’ value to the child process. It is perhaps difficult to visualize this method of process creation because both parent and child are executing the same passage of code. The difference is this: When the return from the fork occurs, the return parameter is tested. If the value is zero, then this is the child crocess, and a branch can be executed to the appropriate user program to continue execution. If the value is nonzero, then this is the parent process, and the main line of execution can continue. I/O Management in UNIX, each individual I/O device is associated with a separate file. These are managed by the file system and are read and written in the same manner as user data files.

In the logical structure, the file subsystem manages file on secondary devices. Also, it serves ,as the process interface to devices, because these are treated as files. Two types. of I/O UNIX i) Buffered

Buffered I/O passes through system buffers. Two types of buffers used in buffered I/O are system buffer caches and character queues. i.i)UnbuIfered Unbuffered I/O involves the DMA facility, with the transfer taking place directly between the I/O module and the process I/O area. Buffer Cache The buffer cache is a disk cache. I/O operations with disk are handled through the buffer cache. The data transfer between the buffer cache and the user process space always occurs using DMA. Because both the buffer cache and the process I/O area are in main memory; the DMA facility is used in this case to perform a memory to memory copy. This does not use up any processor cycles, but it does consume bus cycles. To manage the buffer cache, three lists are maintained: i) Free List List of all slots in the cache that are available for allocation. ii) Device List List of all buffers currently associated with each disk. iii) Driver I/O queue List of buffers that are actually undergoing or waiting for I/O on a particular device The device list is organized as a hash table to minimize the search time. For block replacement, a LRU algorithm is used. After a buffer has been allocated to a disk block ,it cannot be used for another block until all the other buffers have been used more recently. The free list preserves this JRU order. Character Queue A character queue is either written by the I/O device and read by the process or written by the process and read by the device. Character queues may only be read once, as each character is read, it is effectively destroyed. This is in contrast to the buffer cache, which may be read multiple times. Unbuffered I/O Unbuffered I/O, which is simply DMA between device and process space, is always the fastest method for a process to perform I/O. A process that is performing unbuffered I/O is locked in main memory and cannot be swapped out. This reduces the opportunities for swapping by typing up part of main memory, thus reducing the overall system performance. Also, the I/O device is tied up with the process for the duration of the transfer, making it unavailable for other process.