UNIX
Overview of Unix Operating System
Simply stated, UNIX is an operating system. It is by and large the most popular operating system existing today. The features and flexibility of UNIX is so immense that it has become a standard for great many operating systems. It is multi-user system, which means that more than one user can work at the same computer system at the same time. UNIX also supports multi-tasking. Multitasking means that more than one program can be made to run at the same time. For example, you can initiate a program and leave it by itself to go on and in the meantime you can work on some other program. Multi-tasking and multi-user are the two most important characteristics of UNIX, which have helped it gain widespread acceptance among a large variety of users.
The UNIX OS files consume 40 MB of the 80 MB disk space. Another 10-20 MB of disk space is eaten up as swap space. This swap space is used at that point of time when UNIX falls short of memory. So, the contents that are not immediately required are stored in the swap space. Any time when the program needs these contents, they are read from the swap space.
Versions of UNIX
The original version of UNIX actually came from AT&T. Because of the great deal of flexibility offered by UNIX, many new companies emerged and brought out their own variations. Some of the popular versions of UNIX are given in Table below.
Version |
Developed by |
UNIX |
AT&T |
AIX |
IBM |
XENIX |
SCO |
ULTRIX |
DEC (Digital Equipment Corporation) |
UNICOS |
Cray Research |
Sun OS |
Cray Research |
BSD |
University of California at Berkeley |
Dynix |
Sequent |
HP/UX |
Hewlett –Packard |
The original version of UNIX came in the late 1960’s. It was designed by Ken Thompson at AT&T Bell Laboratories. At that point of time, Bell Labs were busy in designing a very big operating system called Multics. Their objective was to provide a very sophisticated and complex multi user system which had support for many advanced features. However, Multics failed because the state of art provided by it at that time was too complex.
Therefore, Bell Labs had to withdraw themselves from the Multics project. Ken Thompson then started working on a simpler project and he named it UNIX. This version of UNIX was rewritten in the year 1973. The source code of UNIX operating system was rewritten in C language by Dennis Ritchie, the inventor of C. In order to make UNIX popular among users, AT & T came up with a unique marketing strategy. They started distributing source copies of UNIX to different universities at a very nominal price. This resulted in the widespread popularity of UNIX. In 1974, Thompson and Ritchie described the UNIX System and got it published in a newspaper named Communications of the ACM. This helped in increasing the acceptance level of the UNIX system even more.
By the year 1977, the UNIX system was installed at around 500 different sites. UNIX system found its major contribution in the telephone companies, providing a good environment for program development, network transaction services and real time services. A large number of institutions and universities were provided licenses of UNIX system. In the year 1977, the UNIX system was first ported from a PDP to a non-PDP machine.
So, as the popularity of UNIX grew, many other companies came out with their own versions of UNIX and ported it onto other new machines. From the year 1977 to 1982, Bell Laboratories combined many AT & T variants into a single system and gave it a name UNIX System III. Many new features and advancements were brought out by Bell Laboratories in this version. It was given the name UNIX System V. The people at University of California at Berkeley developed a variant to the UNIX System. Its recent version is called 4.3 BSD for VAX machines. It provided many new and interesting features.
By the beginning of 1984, UNIX system was installed at about 1,00,000 different computer sites. It ran on a wide range of computers ranging from a mini computer to a mainframe. No other operating system can make such a claim. Many of the programs of the UNIX Operating System are written in C. However, UNIX system can support many other languages also like Fortran, Basic, Pascal, Ada, Cobol, Lisp and Prolog.
UNIX Architecture
The interaction between the user and the hardware happens through the operating system. The operating system interacts directly with the hardware. It provides common services to programs and hides the hardware intricacies from them. The high level architecture of the UNIX system has been shown in Figure (a)
Figure (a)
The hardware of a UNIX system is present in the centre of the diagram. It provides the basic services such as memory management, processor execution level, etc. to the operating system. The UNIX system seems to be organised as a set of layers. The system Kernel is also called the operating system. The user programs are independent of the hardware on which they are running. Therefore, it becomes very easy to run programs on UNIX system running on different hardware if the programs do make special assumptions. The programs such as the shell and editors like (ed and vi) interact with the Kernel by invoking a well defined set of system calls. The system calls get various actions done from the Kernel for the calling program. They interchange data between the Kernel and the program. There are many other programs in this layer which from a part of the standard system configurations. These programs are known as commands. But there are several other user created programs present in the same layer. It is shown by the program whose name is a.out. ‘a. out ‘ is the standard name for all the executable files produced by the C compiler. The outer most layer contains other application programs which can be build on top of lower level programs. For instance, the C compiler, cc, appears in the outermost layer of the figure. It invokes a C preprocessor, compiler, assembler and link loader. These are all separate lower level programs. The programming style offered by the UNIX system helps us to fulfil a task by combining the existing programs.
Features of UNIX
UNIX is such an operating system that can be run on a wide range of machines, from microcomputers to mainframes. There are a variety of reasons which have made UNIX an extremely popular operating system.
Portability
As of today, there are innumerable computer manufacturers all-over the world. Therefore, the hardware configurations keep varying from one vendor to another. The positive and strong thing about UNIX is that it is running successfully on all these computers. The reason behind UNIX’s portability is that it is written in a high-level language which has made it easier to read, understand and change. Its code can be changed and compiled on a new machine. PCs, Amigas, Macintoshes, Workstations, Minicomputers, Super Computers and Mainframes run the UNIX operating system with equal case successfully.
Machine Independent
The UNIX system does not expose the machine architecture to the user. Thus, it becomes very easy to write applications that can run on micros, minis or mainframes.
Multi-user Capability
UNIX is a multi-user system. A multi-user system is a system in which the same computer resources like hard disk, memory etc can be used or accessed by many users simultaneously. Each user is given a terminal (a keyboard and a monitor). Each terminal is an input and an output device for the user. All the terminals are connected to the main computer. So, a user sitting at any terminal can not only use the data or the software of the main computer but also the peripherals like printers attached to it. In UNIX terminology, the main computer is called the server or the console. The number of terminals that can be connected to the server depends upon the number of parts present in the controller card. For instance, an 8- port controller card in the host machine can support 8 terminals.
Multitasking Capability
UNIX has the facility to carry out more than one job at the same time. This feature of UNIX is called multitasking. You can keep typing in a program in its editor while at the same time execute some other command given earlier like copying a file, displaying the directory structure, etc. The latter job is performed in the background and the earlier job in the foreground Multitasking is achieved by dividing the CPU time intelligently between all the jobs that are being carried out. Each job is carried out according to its priority number. Each job gets appropriately small timeslots in the order of milliseconds or microseconds for its execution giving the impression that the tasks are being carried out simultaneously.
Software Development Tools
UNIX offers an excellent environment for developing new software. It provides a variety of tools ranging from editing a program to maintenance of software. It exploits the power of hardware to the maximum extent of effectiveness and efficiency.
Built in Networking
UNIX has got built in networking support with a large number of programs and utilities. It also offers an excellent media for communication with other users. The users have the liberty of exchanging mail, data, programs, etc. You can send your data at any place irrespective of the distance over a computer network.
Security
UNIX supports a very strong security system. It enforces security at three levels. Firstly, each user is assigned a login name and a password. So, only the valid users can have access to the files and directories. Secondly, each file is bound around permissions (read, write, execute). The file permissions decide who can read or modify or execute a particular file. The permissions once decided for a file can also be changed from time to time. Lastly, file encryption comes into picture. It encodes your file in a format that cannot be very easily read. So, if anybody happens to open your file, even then he will not be able to read the text of the file. However, you can decode the file for reading its contents. The act of decoding a coded file is known as decryption.
What makes UNIX Unique
- UNIX and its variants are the only operating systems that are written in a high-level language. This gives it the benefit of machine independence and portability. It becomes very easy to understand, change and move it to other machines.
- It was the first operating system to bring in the concept of hierarchical file structure. It becomes very easy to organise and search for different files.
- It uses a uniform format for files. This makes the application programs to be written easily. This file format is called the byte stream. UNIX treats every file as a stream of bytes. Therefore, the user can manipulate his file in the manner he wants.
- It provides primitives that allow more complex and complicated programs to be built from simpler ones.
- It has a very simple user interface that has the power to provide all the services the users want. It supports both character-based and graphical based user interfaces.
- It hides the machine architecture from the user. This helps the programmer to write different programs that can be made to run on different hardware configurations.
- It provides a simple, uniform interface to peripheral devices.
- It is a multi-user, multiprocess or operating system.
Implementation of Operating System Functions
UNIX System Calls
Now that you have learnt sufficiently about operating systems in general, let us try to learn and appreciate how UNIX operating system performs its designated functions:
- Process management functions : creating, destroying and manipulating processes.
- Memory management functions : allocating, deallocating and manipulating memory.
- Input/Output functions : communicating and controlling I/O device and file system.
- Miscellaneous functions: Network functions etc.
The UNIX System V offers somewhere around 64 system calls. However, only 32 system calls are frequently used. These system calls carry very simple options with them. So, it becomes easy to make use of these system calls. The body of the Kernel is formed by the set of system calls and the internal algorithms that implement them. Thus, the Kernel provides all the services to the application programs in the UNIX system. In the UNIX system, the programs don’t have any knowledge of the internal format in which the Kernel stores file data.
Process management functions
The behavior of a UNIX process is defined by its text segment, data segment and stack segment as shown in Figure (b)
Firgure (b)
The text segment contains the compiled object instructions, the data segment contains static variables, and the stack segment holds the runtime stack used to store temporary variables. A set of source file that is compiled and linked–into an executable form is stored in a file with the dafault name of a. out (of course, the file can be expl¹icitly given any name by the programmer). If the program references statically define data, such as C static variables, a template for the data segment is maintained in the executable file. The data segment will be created and initialized to contain values and space for variables when the executable file is loaded and executed. The stack segment is used to allocate storage for dynamic elements of the program, such as automatic C variables that are created when they come into scope and are destroyed when pass out of scope.
The executable file is created by the compiler and linker. These utilities do not define a process; they define only the program text and a template for the data component that the process will use when it executes the program. When the loader loads a program into the computer’s memory, the system creates appropriate data and stack segments, called a process.
A process has a unique process identifier, a PID, that is essentially a pointer–an integer into a table of process descriptors used by the UNIX OS kernel to reference the process's descriptor. Whenever one process references another process in a system call, it provides the PID of the target process. The UNIX pa command lists each process associated with the user executing the command. The PID of each process appears as a field in the descriptor of each process. The next time you are using UNIX, try the ps - aux command to observe the PID value identifying each process in the system.
The UNIX command for creating a new process is the fork system call. Whenever a (parent) process calls fork, a child process is created with its descriptor, including its own copies of the parent's program text, data, and segments, and access to all open file descriptors (in the kernel). The child and percent processes execute in their own separate address spaces. This means that even though they have access to the same information, both the child and its parent each reference their own copy of the data. No part of the address space of either process is shared. Hence, the parent and child cannot communicate by referencing variables stored at the same address in their respective address space. In UNIX, the only thing the two processes can reference in common is a file.
UNIX systems also provide several forms of the execve system call to enable a process to reload its address space with a different program:
execve (char *path, char *avgv[], char *envp[] );
This system call causes the load module stored in the file at path to replace the program currently being executed by the process. After execve has completed executing, the program that called it, is no longer loaded. Hence, there is no notion of returning from an execve call, since the calling program is no longer loaded in memory. When the new program is started, it is passed the argument list, angv, and the process uses a new set of environment variables, envp.
UNIX also provides a system call, wait (and a frequently used variant, waitpid), to enable a parent process to detect when one of its child processes terminates. Details of the terminating child's status may be either returned to the parent via a value parameter passed to wait or ignored by the parent. The waitpid variant allows the parent to wait for a particular child process (based on its PID) to terminate, while the wait command does not discriminate among child processes. When a process exits, its resources, including the kernel process descriptor, are released. The operating system signals the parent that the child has died, but it will not release the process descriptor until the parent has received the signal. The parent executes the wait call to acknowledge the termination of a child process.
The parent program shown in Figure 6.3 illustrates how execve and wait can be used. In this complete example, the parent process creates a child using the fork command and then simulates execution with the printf and sleep function calls.
A Simple Parent Program
#include#define NULL 0
int main (void) {
if (fork() = = 0) { /* This is the child process */
execve (“child”, NULL, NULL);
exit (0); /* Should never get here, terminate */
}
/* Parent code here */
printf (“Process [%d]: Parent in execution…./n”,
getpid ());
sleep (2);
if (Wait (NULL) > 0) /* Child terminating */
printf (“Process [%d]: Parent detects terminating child /n”,
getpid ());
printf (“Process [%d]: Parent terminating…/n”, getpid());
}
In a more practical application, the parent would execute from its own address space in place of the printf and sleep calls.
You have just learnt how to use UNIX system calls. Following are the rest of UNIX system calls related to process management:
acct : enable/disable process accounting
alarm : set a process alarm clock
exit : terminate a process
fork : create a new process
getpid : get process, process group and parent process ID
getuid : get real user, effective user real group and effective
group ID
kill : send a signal to a process or group of processes
msgctl : message control operation
msgop : message operation
nice : change priority of a process
pause : suspend until
pipe : create an inter-process channel
profil : execution time profile
ptrace : process trace
semctl : semaphor control operations
semget : get set of semaphor
semop : semaphor operations
setpgrp : set process group ID
setuid : set group and user ID
signal : specify what to do when a signal is received
stime : set time
sync : update super block
time : get time
times : get process and child process times
ulimit : get user upper limits
uname : get the name of the current operating system
ulink : remove directory entry
Wait : wait for the child process to stop or terminate
All these function calls are used more or less the same way. Some of the most important of them will be explained through this unit.
NOTE : The Next Part Of This Article Will Be on Boddunan As Soon As Possible.
Lohit seth