Functions of the

UNIX Operating System 

 

 

 

 

 

 

 

By: James Wright

 

 

 

 

 

Copyright © 2003 Saba Computer Consulting

 

 

 

 

 

 

 

 

 

 

 

Contains

 

Function 1: Process Management,

Function 2: Memory Management,

Function 3: File System

Function 4: User Interface

 


Function 1: Process Management

 

            A key difference in the UNIX operating system is that there is ease in the sense that multiple processes can be manipulated and created easily.  Such processes are seen in UNIX within control blocks.  Information within the control blocks is accessed and used by the kernel and CPU for scheduling.

A process control block contains everything the system needs to know about that particular process and all its unique identifiers.  These exist within a process data structure for these processes.  The virtual address space of a process is divided into text, data, and stack segments.  Every process with shareable text has something called a pointer for its process structure to a text structure.  In the text structure it records how many processes are assigned to the text segment along with a pointer to a list of those process structures then to a page table for the text segment.

Page tables are records of information on the mapping of the processes in virtual memory to physical memory.  The process structure, as stated earlier, has pointers to this page table and are used when the process is resident in main memory or the address on the process when it is swapped.

Information about processes that is only needed when it is not swapped out is kept in a user structure rather than the process structure.  This structured is mapped as read-only into user virtual address space, so the user processes can read the contents.

Each process has a user and a system phase and most work is done in user mode, however when a system call is made then it is performed in system mode.  These modes do not act at the same time.  When a process is executing in system mode the kernel stack for the process is used.  The kernel stack and the user structure compose of a system data segment for a process.

            CPU scheduling was designed to be best used for interactive processes.  These processes are allocated small CPU slices of time by an algorithm.  This algorithm uses a priority to reduce the round robin scheduling for jobs going to the CPU.  These processes have a scheduling priority as mentioned earlier.  Larger numbers means the process has lower priority and vice versa.  Processes, for example, that do i/o (a very important process) have priorities that are less than zero and can not be terminated by signals.  User processes on the other hand have a lower level priority.  This is perhaps a reason why UNIX is a strong system orientated environment that gives priority to the system/OS rather than to the user itself. 

As time goes on in a process its priority becomes lower and lower, till eventually it is taken over by another process of higher priority.  This in itself sounds like a good method of CPU scheduling as no one process can use the CPU for a long time before it must give up access rights.

 

Function 2: Memory Management

 

            Swapping in UNIX is used to handle memory contention among processes.  If there is too much contention then the processes are swapped out until memory is available for more.  Allocating data in main memory and swap space is done by whatever fits first.  Decisions on whether or not to swap processes in or out are made by the scheduler process which is known as the swapper.  Every 4 seconds the scheduler wakes up to check these processes to be swapped in or out.  The longer the process is idle, the more likely it is to be swapped then processes are picked by age. 

An important thing is implemented to fix thrashing (immense cpu usage then lockup) which basically is not letting a process to be swapped out if it hasn’t been in memory for a decent amount of time.  Swapping is only one method used in UNIX for memory contention, the next is called Paging.

            Paging within UNIX was introduced by Berkeley.  External fragmentation of memory is eliminated by the use of paging..  For example, swapping is kept to a minimum because more jobs can be kept in main memory by the use of paging which allows execution with only parts of each process in memory.  Paging works like so – when a process needs a page and the page is not there, a page fault to the kernel happens.  A frame of main memory is then allocated and the disk page is read into the frame.  A few optimizations are in place, such as, if the page that is needed is in the page table it can be marked valid then used without any i/o transfer.  If a page has to be taken from a disk then it is locked in memory for the duration.  Locking it ensures the page will not be used or selected for page replacement.  Once it is used and mapped it must remain locked if physical i/o is being done to it.

 

Function 3: File System

 

            In a UNIX file system there are two main objects: files and directories.  Directories are seen as a file with a special format.  Representation of a file is a basic concept in UNIX.

            The UNIX system data is taken up in data blocks which contains most of what users put in their files.  However, it is important to consider how these files are put on the disk.  For instance, a hard disk sector is about 512 bytes.  Block sizes higher than 512 is wanted for speed but Unix files usually contain a lot of small files, being much larger blocks would cause a lot of internal fragmentation.  The use of smaller files and decreased fragmentation would be another key attribute why UNIX is known to work faster than Windows overall. 

Block and fragment sizes are set during system creation depending on what the intended use of it was.  For example, if many small files are to be used, the fragment size should be small and if there is going to be repeated transfers for large files then the block size should be larger.  Block to fragment ratio is about 8:1 with a minimum block being 4k.

            Inode is a record that represents and stores information about specific files on disk and at one time was called an Index Node.  These inodes contain user and group identifiers, file modification and access, hard links, type of file, etc.  Inodes have 15 pointers to disk blocks that contain data contents of the file.  The first 12 point to direct blocks, the next three to indirect blocks. 

More importantly, since directories are not seen as any different than files, the inode is the key to seeing a separation.  The inode type field distinguishes between plain files and directories.  The first two names of every directory begins with a period or a double period and linear searches are used to create new directories after existing files.  The user refers to a directory structure by path and file name, where the file system uses the inode for its definition.  These inodes are the heart of the file system within UNIX.

 

Function 4: User Interface

 

            Usage of the UNIX interface does not come without its quirks and loss of GUI.  You will deal mainly with a common set of system programs that are available for executions.  These programs make the system calls to support a function however the system calls are contained within this program and are not needed to be displayed to the user.

Common system programs for example:

 

Mkdir

Make a directory

Rmdir

Remove a directory

Cd

Change Directory

Pwd

Print path name of working directory

Ls

Lists the names of the files in the directory

Cp

Creates a new file that is a copy of another

Rm

Deletes a file

Run

Executes a program

 

 

A Shell in UNIX is a program that surrounds the kernel of the Operating System.  Users write their own shell and there are also several shells that are used generally.  In general shells use a common syntax.  Processes open files as they like however most processes desire three file descriptors.  They are known as standard input, standard output, and standards error.