Unix Progrmng
Unix Progrmng
UNIT I
Unix is a powerful, multiuser, and multitasking operating system that was originally developed in
the 1960s at Bell Labs by Ken Thompson, Dennis Ritchie, and others. It is the foundation for
many other operating systems, including Linux, macOS, and even the underlying system for
Android. Unix's design is centered around simplicity and modularity, which allows users to
perform complex tasks by combining simple tools.
Multi-user: UNIX operating system supports more than one user to access computer
resources like main memory, hard disk, tape drives, etc. Multiple users can log on to the
system from different terminals and run different jobs that share the resources of a
command terminal. It deals with the principle of time-sharing. Time-sharing is done by a
scheduler that divides the CPU time into several segments also called a time slice, and
each segment is assigned to each user on a scheduled basis. This time slice is tiny.
When this time is expired, it passes control to the following user on the system. Each
user executes their set of instructions within their time slice.
Portability: This feature makes the UNIX work on different machines and platforms with
the easy transfer of code to any computer system. Since a significant portion of UNIX is
written in C language, and only a tiny portion is coded in assembly language for specific
hardware.
File Security and Protection: Being a multi-user system, UNIX makes special
consideration for file and system security. UNIX has different levels of security using
assigning username and password to individual users ensuring the authentication, at the
level providing file access permission viz. read, write and execute and lastly file
encryption to change the file into an unreadable format.
Command Structure: UNIX commands are easy to understand and simple to use.
Example: "cp", mv etc. While working in the UNIX environment, the UNIX commands are
case-sensitive and are entered in lower case.
Open Source: UNIX operating system is open source it means it is freely available to all
and is a community-based development project.
Accounting: UNIX keeps an account of jobs created by the user. This feature enhances
the system performance in terms of CPU monitoring and disk space checking. It allows
you to keep an account of disk space used by each user, and the disk space can be
limited by each other. You can assign every user a different disk quota. The root user can
perform these accounting tasks using various commands such as quota, df, du, etc.
UNIX Tools and Utilities: UNIX system provides various types of tools and utilities
facilities such as UNIX grep, sed and awk, etc. Some of the general-purpose tools are
compilers, interpreters, network applications, etc. It also includes various server
programs which provide remote and administration services.
The structure of Unix OS Layers are as follows:
While working with UNIX OS, several layers of this system provide interaction between
the pc hardware and the user. Following is the description of each and every layer
structure in UNIX system:
Layer-1: Hardware -
This layer of UNIX consists of all hardware-related information in the UNIX environment.
Layer-2: Kernel -
The core of the operating system that's liable for maintaining the full functionality is
named the kernel. The kernel of UNIX runs on the particular machine hardware and
interacts with the hardware effectively.
It also works as a device manager and performs valuable functions for the processes
which require access to the peripheral devices connected to the computer. The kernel
controls these devices through device drivers.
The kernel also manages the memory. Processes are executed programs that have
owner's humans or systems who initiate their execution.
The system must provide all processes with access to an adequate amount of memory,
and a few processes require a lot of it. To make effective use of main memory and to
allocate a sufficient amount of memory to every process. It uses essential techniques
like paging, swapping, and virtual storage.
Layer-3: The Shell -
The Shell is an interpreter that interprets the command submitted by the user at the
terminal, and calls the program you simply want.
It also keeps a history of the list of the commands you have typed in. If you need to
repeat a command you typed it, use the cursor keys to scroll up and down the list or
type history for a list of previous commands. There are various commands like cat, mv,
cat, grep, id, wc, and many more.
o Bourne Shell: This Shell is simply called the Shell. It was the first Shell for UNIX OS. It is
still the most widely available Shell on a UNIX system.
o C Shell: The C shell is another popular shell commonly available on a UNIX system. The C
shell was developed by the University of California at Berkeley and removed some of the
shortcomings of the Bourne shell.
o Korn Shell: This Shell was created by David Korn to address the Bourne Shell's user-
interaction issues and to deal with the shortcomings of the C shell's scripting quirks.
Layer-4: Application Programs Layer -
It is the outermost layer that executes the given external applications. UNIX distributions
typically come with several useful applications programs as standard. For
Example: emacs editor, StarOffice, xv image viewer, g++ compiler etc.
RT Examples
The architecture of Unix systems is designed to be modular, efficient, and flexible. It consists of several key
components that work together to provide a stable and powerful operating environment. Here’s an overview of
Unix architecture with real-time examples:
1. Kernel
Description: The kernel is the core component of the Unix operating system. It manages hardware resources,
provides system services, and enforces system security. The kernel handles tasks such as process management,
memory management, device management, and system calls.
Real-Time Example:
Example: A Linux-based server running a web application uses the kernel to manage multiple
simultaneous user requests. The kernel allocates CPU time, manages memory, and handles I/O
operations to ensure that the web server can handle high traffic efficiently.
2. Shell
Description: The shell is the command-line interface (CLI) that allows users to interact with the operating
system. It interprets user commands and executes them by invoking system calls to the kernel. Shells can be
interactive (command line) or script-based (shell scripts).
Real-Time Example:
Example: A system administrator uses the Bash shell to automate routine tasks by writing shell scripts.
For instance, a script that backs up critical data daily by copying files from a server to a remote storage
location is executed via the shell.
3. File System
Description: The file system organizes and manages files and directories on disk. It provides a hierarchical
structure where files are stored in directories, and it handles file operations like reading, writing, and permission
management.
Real-Time Example:
Example: On a Linux desktop, the file system manages user files in the /home directory. For instance, a
user’s documents, images, and configuration files are all organized in subdirectories under
/home/username.
4. System Calls
Description: System calls are the programming interface between user applications and the kernel. They allow
user programs to request services from the kernel, such as file operations, process control, and communication.
Real-Time Example:
Example: A text editor application uses system calls to open, read, and write files. When a user saves a
document, the editor makes system calls to write data to the file system.
Description: Processes are instances of running programs. Each process has its own memory space and
resources. Threads are lightweight processes within a process that share the same memory space but can
execute independently.
Real-Time Example:
Example: A web server like Apache runs multiple processes to handle different client requests
simultaneously. Each process can create threads to manage individual connections, allowing the server
to handle many requests efficiently.
Description: Unix systems manage users and groups to control access to files and system resources. Each user
has a unique user ID (UID), and groups have unique group IDs (GIDs). Permissions are assigned based on users
and groups.
Real-Time Example:
Example: In a multi-user environment, such as a university computer lab, each student has their own
user account. The system administrator assigns permissions so that students can only access their own
files and directories, ensuring privacy and security.
Description: IPC mechanisms allow processes to communicate and synchronize with each other. Common IPC
methods include pipes, message queues, semaphores, and shared memory.
Real-Time Example:
Example: A web application might use IPC to coordinate between a web server process and a database
process. For instance, a message queue could be used to send queries from the web server to the
database for processing.
8. Device Drivers
Description: Device drivers are specialized programs that allow the kernel to interact with hardware devices.
They provide the necessary interface between the hardware and the operating system.
Real-Time Example:
Example: A Linux server uses device drivers to manage network interfaces. When data is transmitted
over the network, the network device driver handles communication between the network card and the
kernel.
9. Libraries
Description: Libraries are collections of precompiled routines that applications can use. They provide standard
functions and routines to perform common tasks, such as mathematical operations or file handling.
Real-Time Example:
Example: A software application on a Unix-based system might use the GNU C Library (glibc) for
standard functions such as memory allocation and string manipulation, simplifying development and
ensuring compatibility across different systems.
Description: Configuration files store settings and preferences for the operating system and applications. They
are typically located in the /etc directory and are used to customize system behavior.
Real-Time Example:
Summary
Unix architecture is designed to be modular and efficient, with components that work together to provide a
stable and secure operating environment. From managing hardware resources with the kernel to interacting with
users through the shell and handling files with the file system, each part of the Unix architecture plays a critical
role in supporting a wide range of real-time applications and use cases.
Unix is a versatile operating system widely used across different domains due to its stability, security, and
flexibility. Here are some real-time examples of where Unix is used:
1. Web Servers
2. Database Servers
Use Case: Managing large-scale databases that store critical business information.
Example: Oracle Database often runs on Unix-based systems because of their ability to handle high
transaction volumes and ensure data integrity. Financial institutions, for example, use these systems to
manage their databases securely and efficiently.
Reason: Unix’s strong multitasking and multiuser capabilities allow it to handle complex database
operations without downtime.
5. Development Environments
7. Cybersecurity
8. Embedded Systems
9. Cloud Computing
Unix's versatility and reliability make it an indispensable tool across various industries and applications, from
powering the internet to driving scientific research and managing enterprise IT infrastructure.