0% found this document useful (0 votes)
36 views30 pages

Unit - V

UNIX FILE SYSTEM

Uploaded by

tnagalaxmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views30 pages

Unit - V

UNIX FILE SYSTEM

Uploaded by

tnagalaxmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

UNIT – V

 File System

 Concepts of Process

 Concurrent execution & Interrupts

 Process management-forks

 Basic level programming with system calls

 Shell programming and filters, UNIX Signals, POSIX Standards


Introduction
• The kernel is a computer program at the core of a computer’s OSwith complete
control over everything in the system.
• It is an integral part of any operating system.
• It is the "portion of the operating system code that is always resident in memory”.
It facilitates interactions between hardware and software components.

• A Unix kernel — the core or key components of the operating system — consists
of many kernel subsystems like process management, scheduling, file
management, device management and network management, memory
management, dealing with interrupts from hardware devices.
Architecture of UNIX:
The UNIX operating system is made up of three parts; the kernel, the shell, the Commands and Utilities, the Files and Directories
• Kernel: The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the files management and
communications in response to system calls.
• Shell: The shell is the utility that processes your requests. When you type in a command at your terminal, the shell interprets the command and
calls the program that you want. The shell uses standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the most famous
shells which are available with most of the Unix variants.
• Commands and Utilities: There are various commands and utilities which you can make use of in your day to day activities. cp, mv, cat and grep,
etc. are few examples of commands and utilities. There are over 250 standard commands plus numerous others provided through 3rd party
software. All the commands come along with various options.
• Files and Directories: All the data of Unix is organized into files. All files are then organized into directories. These directories are further
organized into a tree-like structure called the file system
UNIX File system:

• Unix file system is a logical method of organizing and storing large amounts of information in a way
that makes it easy to manage.
• A file is a smallest unit in which the information is stored.
• Unix file system has several important features.
• All data in Unix is organized into files.
• All files are organized into directories.
• These directories are organized into a tree-like structure called the file system.
Hierarchical structure of UNIX file system: Files in Unix System are organized into multi-level hierarchy
structure known as a directory tree.
At the very top of the file system is a directory called “root” which is represented by a “/”.
All other file are “descendants” of root.

Directories or Files and their description


 / : The slash / character alone denotes the root of the filesystem tree.
 /bin : Stands for “binaries” and contains certain fundamental utilities,
such as ls or cp, which are generally needed by all users.
 /boot : Contains all the files that are required for successful booting
process.
 /dev : Stands for “devices”. Contains file representations of peripheral
devices and pseudo- devices.
 /etc : Contains system-wide configuration files and system databases.
Originally also contained “dangerous maintenance utilities” such as
init,but these have typically been moved to /sbin or elsewhere.
 /home : Contains the home directories for the users.
 /lib : Contains system libraries, and some critical files such as kernel
modules or device drivers.
 /media : Default mount point for removable devices, such as USB sticks,
media players, etc.
 /mnt : Stands for “mount”. Contains filesystem mount points. These are
used, for example, if the system uses multiple hard disks or hard disk
partitions. It is also often used for remote (network) filesystems, CD-
ROM/DVD drives, and so on.
 /proc : procfs virtual filesystem showing information about processes as
files.
/root : The home directory for the superuser “root” – that is, the system
administrator.
TYPES of Files in UNIX
1.Ordinary files – An ordinary file is a file on the system that contains data, text, or program instructions.
file is specified by the “-” symbol.
2.Special Files – Used to represent a real physical device such as a printer, tape drive or terminal, used for Input/Ouput
(I/O) operations. Device or special files are used for device .
On UNIX systems there are two flavors of special files for each device, character special files and block special files :
 When a character special file is used for device Input/Output(I/O), data is transferred one character at a time. This type of access is called raw device access.

When a block special file is used for device Input/Output(I/O), data is transferred in large fixed-size blocks. This type of access is called block device access
 character special files are marked by the “c” symbol.
 block special files are marked by the “b” symbol.

3.Directories – Directories store both special and ordinary files

4.A pipe simply refers to a temporary software connection between two programs or commands. An area of the main
memory is treated like a virtual file to temporarily hold data and pass it from one process to another in a single direction. In

OSes like Unix, a pipe passes the output of one process to another process. UNIX allows you to link commands

together using a pipe. The pipe acts a temporary file which only exists to hold data from one command until it
is read by another.
To make a pipe, put a vertical bar (|) on the command line between two commands. For example: who | wc -l
• named pipes are marked by the “p” symbol
5. Sockets – A Unix socket (or Inter-process communication socket) is a special file which allows for
advanced inter-process communication. It allows two different processes on the same or different machines.
It is the way to talk to other computers using standard unix file descriptors. A Unix Socket is used in a client-
server application framework. In essence, it is a stream of data, very similar to network stream (and network
sockets), but all the transactions are local to the filesystem.
• Unix sockets are marked by “s” symbol.

6. Symbolic Link – Symbolic link is used for referencing some other file of the file system. Symbolic link is
also known as Soft link. It contains a text form of the path to the file it references. To an end user, symbolic
link will appear to have its own name, but when you try reading or writing data to this file, it will instead
reference these operations to the file it points to. If we delete the soft link itself , the data file would still be
there. If we delete the source file or move it to a different location, symbolic file will not function properly.
• Symbolic link are marked by the “l” symbol (that’s a lower case L).
PROCESS:
• Process: A process is defined as an entity which represents the basic unit of work to be implemented in the system. An instance of

a running program is called a process. Every time you run a shell command, a program is run and a process is created for it.

• Each process in Unix has a process id (PID) and it is associated with a particular user and group account.

• Unix is a multiprocessing operating system, its objective is to have a process running on each CPU in the system at all times, to

maximize CPU utilization. If there are more processes than CPUs (and there usually are), the rest of the processes must wait

before a CPU becomes free until they can be run. The kernel itself is not a process but a process manager.

• The process/kernel model assumes that processes that require a kernel service use specific programming constructs called system

calls.

• Each system call sets up the group of parameters that identifies the process request and then executes the hardware-dependent

CPU instruction to switch from User Mode to Kernel Mode. "Real time" (for a process) refers to the scheduling algorithm, or the

thinking the kernel does when it decides which process gets to run.

• A real time process will preempt all other processes (of lesser scheduling weight) when an interrupt is received and it needs to run
Concurrent Execution & Interrupts:
• Concurrency is the execution of the multiple instruction sequences at the same time. It happens in the operating system when there are several
process threads running in parallel. The running process threads always communicate with each other through shared memory or message passing.
Concurrency results in sharing of resources result in problems like deadlocks and resources starvation.
• It helps in techniques like coordinating execution of processes, memory allocation and execution scheduling for maximizing throughput.
• Principles of Concurrency:
• Both interleaved and overlapped processes can be viewed as examples of concurrent processes, they both present the same problems.
• The relative speed of execution cannot be predicted. It depends on the following:
• The activities of other processes
• The way operating system handles interrupts
• The scheduling policies of the operating system
Problems in Concurrency:
• Sharing global resources Sharing of global resources safely is difficult. :- If two processes both make use of a global variable and both perform read
and write on that variable, then the order iin which various read and write are executed is critical.
• Optimal allocation of resources It is difficult for the operating system to manage the allocation of resources optimally.
• Locating programming errors It is very difficult to locate a programming error because reports are usually not reproducible.
• Locking the channel It may be inefficient for the operating system to simply lock the channel and prevents its use by other processes
Drawbacks of Concurrency
• It is required to protect multiple applications from one another.
• It is required to coordinate multiple applications through additional mechanisms.
• Additional performance overheads and complexities in operating systems are required for switching
among applications.
• Sometimes running too many applications concurrently leads to severely degraded performance.
Issues of Concurrency:
• Non-atomic – Operations that are non-atomic but interruptible by multiple processes can cause
problems.
• Race conditions A race condition occurs of the outcome depends on which of several processes gets
to a point first.
• Blocking – Processes can block waiting for resources. A process could be blocked for long period of
time waiting for input from a terminal. If the process is required to periodically update some data, this
would be very undesirable.
• Starvation It occurs when a process does not obtain service to progress.
• Deadlock It occurs when two processes are blocked and hence neither can proceed to execu
Interrupts:
• An interrupt is an event that changes the sequence of instructions executed by the processor.
• There are two different kinds of interrupts:
1. Synchronous interrupt (Exception) produced by the CPU while processing instructions
2. Asynchronous interrupt (Interrupt) issued by other hardware devices.
• Exceptions are caused by programming errors (i.e. Divide error, Page Fault, Overflow) that must be handled by the kernel. He sends a signal to the
program and tries to recover from the error. The following two exceptions are classif
• Processor-detected exception generated by the CPU while detecting a anomalous condition; divided into three groups: Faults can generally be
corrected, Traps report an execution, Aborts are serious errors.
• Programmed exception requested by the programmer, handled like a trap. Interrupts can be issued by I/O devices (keyboard, network
adapter, ...), interval timers and (on multiprocessor systems) other CPUs. When an interrupt occurs, the CPU must stop his current instruction and execute the
newly arrived interrupt. He needs to save the old interrupted process state to (probably) resume it after the interrupt is handled. Handling interrupts is a
sensitive task:
• Interrupts can occur at any time; the kernel tries to get it out of the way as soon as possible:
• An interrupt can be interrupted by another interrupt
• There are regions in the kernel which must not be interrupted at all.

Two different interrupt levels are defined:


• Maskable interrupts issued by I/O devices; can be in two states, masked or unmasked. Only unmasked interrupts are getting processed.
• Nonmaskable interrupts; critical malfunctions (i.e. hardware failure); always processed by the CPU.
Every hardware device has its own Interrupt Request (IRQ) line. The IRQs are numbered starting from 0. All IRQ lines are connected to a Programmable
Interrupt Controller (PIC). The PIC listens on IRQs and assigns them to the CPU. It is also possible to disable a specific IRQ line.
Process Management:
• A process is usually defined as the instance of the running program. Process management is an integral part of any modern
day operating system (OS). Process management describes how the operating systems manage the multiple processes
running at a particular instance of time.
• The OS must allocate resources to processes, enable processes to share and exchange information, protect the resources of
each process from other processes and enable synchronization among processes. To meet these requirements, the OS must
maintain a data structure for each process, which describes the state and resource ownership of that process, and which
enables the OS to exert control over each process.
• Several processes can run at the same time and must all be handled by the operating system. The kernel needs to maintain
data for each process it is running. The data tells the OS in what state the process is, what les are open, which user is running
it, etc. The information is maintained in a process structure is also called Process Control Block (PCB).
• The operating system tracks processes through a five-digit ID number known as the pid or the process ID. Each process in
the system has a unique pid.
• Pids eventually repeat because all the possible numbers are used up and the next pid rolls or starts over. At any point of time,
no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process.
fork() and exec()
• Every application(program) comes into execution through means of process, process is a running instance of a program. Processes are
created through different system calls, most popular are fork() and exec().

• Fork creates a new process by duplicating the calling process, The new process, referred to as child, is an exact duplicate of the calling
process, referred to as parent, except for the following:
• 1. The child has its own unique process ID, and this PID does not match the ID of any existing process group.
• 2. The child’s parent process ID is the same as the parent’s process ID.
• 3. The child does not inherit its parent’s memory locks and semaphore adjustments.
• 4. The child does not inherit outstanding asynchronous I/O operations from its parent nor does it inherit any asynchronous I/O contexts from
its parent.

• Return value of fork() On success, the PID of the child process is returned in the parent, and 0 is returned in the child. On failure, -1 is
returned in the parent, no child process is created, and err no is set appropriately.

• Exection family of functions replaces the current process image with a new process image. It loads the program into the current process
space and runs it from the entry point.

• The main difference between fork and execution is: The fork system call creates a new process. The new process created by fork() is a
copy of the current process except for the returned value. The exec() system call replaces the current process with a new programby
SYSTEM CALLS
Some of the system calls are:
3 main common unix signals:
Unix signals
Posix signals

You might also like