OS BCA-sem3(UNIT4)
OS BCA-sem3(UNIT4)
UNIT – 4
Operating System
MAYUR PARMAR
(ASSISTANT PROFESSOR OF SMT V. V, SHAH
M.SC(CA&IT) INSTITUTE, MODASA
In general, a file is a sequence of bits, bytes, or records whose meaning is defined by the file
creator and user. Every File has a logical location where they are located for storage and
retrieval.
• Files have names and are associated with access permission that permits controlled
sharing.
• Files could be arranged or more complex structures to reflect the relationship between
them.
File structure
A File Structure needs to be predefined format in such a way that an operating system
understands. It has an exclusively defined structure, which is based on its type.
File Attributes
A file has a name and data. Moreover, it also stores meta information like file creation date and
time, current size, last modified date, etc. All this information is called the attributes of a file
system.
File Type
It refers to the ability of the operating system to differentiate various types of files like text files,
binary, and source files. However, Operating systems like MS_DOS and UNIX has the following
type of files:
Ordinary files
Directory Files
• Directory contains files and other related information about those files. Its basically a
folder to hold and organize multiple files.
Special Files
• These files are also called device files. It represents physical devices like printers, disks,
networks, flash drive, etc.
Developed By: - Asst.Prof. Mayur Parmar
Page 3
Operating System
Functions of File
• Create file, find space on disk, and make an entry in the directory.
• Write to file, requires positioning within the file.
• Delete directory entry, regain disk space.
• Reposition: move read/write position.
Field:
This element stores a single value, which can be static or variable length.
DATABASE:
Collection of related data is called a database. Relationships among elements of data are explicit.
FILES:
Files is the collection of similar record which is treated as a single entity.
RECORD:
A Record type is a complex data type that allows the programmer to create a new data type with
the desired column structure. Its groups one or more columns to form a new data type. These
columns will have their own names and data type.
• Sequential access
• Direct random access
• Index sequential access
Sequential Access
In this type of file access method, records are accessed in a certain pre-defined sequence. In the
sequential access method, information stored in the file is also processed one by one. Most
compilers access files using this access method.
Random Access
The random access method is also called direct random access. This method allow accessing the
record directly. Each record has its own address on which can be directly accessed for reading
and writing.
Sequential Access
This type of accessing method is based on simple sequential access. In this access method, an
index is built for every file, with a direct pointer to different memory blocks. In this method, the
Index is searched sequentially, and its pointer can access the file directly.
Space Allocation
In the Operating system, files are always allocated disk spaces.
• Linked Allocation
• Indexed Allocation
• Contiguous Allocation
Contiguous Allocation
In this method,
Linked Allocation
In this method,
Indexed Allocation
In this method
Directory comprises the addresses of index blocks of the specific files.
• An index block is created, having all the pointers for specific files.
• All files should have individual index blocks to store the addresses for disk space.
File Directories
A single directory may or may not contain multiple files. It can also have sub-directories inside
the main directory. Information about files is maintained by Directories. In Windows OS, it is
called folders.
What Is UNIX?
Why UNIX?
• Hardware independence
o operating system code is written in C language rather than a specific assembly
language
o operating system software can be easily moved from one hardware system to
another
o UNIX applications can be easily moved to other UNIX machines. Porting is
usually as simple as transfer of the source and a recompile
• Productive environment for software development
o rich set of tools
o versatile command language
• Distributed processing and multi-tasking
Features of UNIX
Unix is an operating system, so it has all the features that the OS must-have. UNIX also looks
at a few things in a different way than other OS. Features of UNIX are listed below :
1. Multiuser System :
Unix provides multiple programs to run and compete for the attention of the CPU. This
happens in 2 ways :
• Multiple users running multiple jobs
• Single user running multiple jobs
2. Multitask System :
A single user may run multiple tasks concurrently. Example : Editing a file, printing another on
the printer & sending email to a person, and browsing the net too at the same time. The Kernel
is designed to handle user’s multiple needs.
The important thing here is that only one job can be seen running in the foreground, the rest all
seems to run in the background. Users can switch between them, terminate/suspend any of the
jobs.
3. The Building-Block Approach :
The Unix developers thought about keeping small commands for every kind of work. So Unix
has so many commands, each of which performs one simple job only. You can use 2
commands by using pipes (‘|’). Example : $ ls | wc Here, | (pipe) connects 2 commands to
create a pipeline. This command counts the number of files in the directory.
4. Pattern Matching :
Unix provides very sophisticated pattern matching features. The meta-char ‘*’ is a special
character used by the system to match a number of file names. There are several other meta-
char in UNIX. The matching is not confined to only filename. Advanced tools use a regular
expression that is framed with the characters from this set.
5. Programming Facility :
Unix provides shell which is also a programming language designed for programmers, not for
casual end-users. It has all the control structures, loops, and variables required for
programming purposes.
6. Documentation :
It has a ‘man’ command that stands for the manual, which is the most important reference for
any commands and their configuration files. Apart from the online documentation, there is a
vast amount of resources available on the Internet. If you’re stuck with a problem, there are
various UNIX newsgroups where you can post your concerns..
What is Kernel?
In computer science, Kernel is a computer program that is a core or heart of an operating
system. Before discussing kernel in detail, let's first understand its basic, i.e., Operating system in
a computer.
o As discussed above, Kernel is the core part of an OS(Operating system); hence it has full
control over everything in the system. Each operation of hardware and software is
managed and administrated by the kernel.
o It acts as a bridge between applications and data processing done at the hardware level. It
is the central component of an OS.
o It is the part of the OS that always resides in computer memory and enables the
communication between software and hardware components.
o It manages other tasks also such as memory management, task management, and disk
management.
o Other application programs such as browser, word processor, audio & video player use
separate memory space known as user-space.
Functions of a Kernel
• Device Management
• Memory Management
• Resource Management
• Accessing Computer Resources
• Random-Access Memory
Types of Kernel
1. Monolithic Kernels
In a monolithic kernel, the same memory space is used to implement user services and kernel
services.
As it uses the same memory space, the size of the kernel increases, increasing the overall size of
the OS.
Examples of Monolithic Kernels are Unix, Linux, Open VMS, XTS-400, etc.
2. Microkernel
A microkernel is also referred to as μK, and it is different from a traditional kernel or Monolithic
Kernel. In this, user services and kernel services are implemented into two different address
spaces: user space and kernel space.
3. Hybrid Kernel
Hybrid kernels are also known as modular kernels, and it is the combination of both Monolithic
and Microkernels. It takes advantage of the speed of monolithic kernels and the modularity of
microkernels.
4. Nanokernel
As the name suggests, in Nanokernel, the complete code of the kernel is very small, which
means the code executing in the privileged mode of the hardware is very small. Here the term
nano defines a kernel that supports a nanosecond clock resolution.
5. Exokernel
Exokernel is still developing and is the experimental approach for designing OS.
This type of kernel is different from other kernels as in this; resource protection is kept separated
from management, which allows us to perform application-specific customization.
Basic Commands:
1. pwd command
Use the pwd command to find out the path of the current working directory (folder) you’re in.
The command will return an absolute (full) path, which is basically a path of all the
directories that starts with a forward slash (/). An example of an absolute path
is /home/username.
2. cd command
To navigate through the Linux files and directories, use the cd command. It requires either the
full path or the name of the directory, depending on the current working directory that you’re
in.
Let’s say you’re in /home/username/Documents and you want to go to Photos, a
subdirectory of Documents.
There are some shortcuts to help you navigate quickly:
3. ls command
The ls command is used to view the contents of a directory. By default, this command will
display the contents of your current working directory.
If you want to see the content of other directories, type ls and then the directory’s path. For
example, enter ls /home/username/Documents to view the content of Documents.
There are variations you can use with the ls command:
• ls -al will list the files and directories with detailed information like the permissions,
size, owner, etc.
4. cat command
cat (short for concatenate) is one of the most frequently used commands in Linux. It is used
to list the contents of a file on the standard output (sdout). To run this command,
type cat followed by the file’s name and its extension. For instance: cat file.txt.
Here are other ways to use the cat command:
• cat filename1 filename2>filename3 joins two files (1 and 2) and stores the output
of them in a new file (3)
• to convert a file to upper or lower case use, cat filename | tr a-z A-Z >output.txt
5. cp command
Use the cp command to copy files from the current directory to a different directory. For
instance, the command cp scenery.jpg /home/username/Pictures would create a copy
of scenery.jpg (from your current directory) into the Pictures directory.
6. mv command
The primary use of the mv command is to move files, although it can also be used to rename
files.
The arguments in mv are similar to the cp command. You need to type mv, the file’s name, and
the destination’s directory. For example: mv file.txt /home/username/Documents.
To rename files, the Linux command is mv oldname.ext newname.ext
7. mkdir command
Use mkdir command to make a new directory — if you type mkdir Music it will create a
directory called Music.
There are extra mkdir commands as well:
• To generate a new directory inside another directory, use this Linux basic
command mkdir Music/Newfile
• use the p (parents) option to create a directory in between two existing directories.
For example, mkdir -p Music/2020/Newfile will create the new “2020” file.
8. rmdir command
If you need to delete a directory, use the rmdir command. However, rmdir only allows you
to delete empty directories.
9. rm command
The rm command is used to delete directories and the contents within them. If you only
want to delete the directory — as an alternative to rmdir
Another basic Linux command that is undoubtedly helpful for everyday use is grep. It lets
you search through all the text in a given file.
To illustrate, grep blue notepad.txt will search for the word blue in the notepad file. Lines that
contain the searched word will be displayed fully.
Short for difference, the diff command compares the contents of two files line by line. After
analyzing the files, it will output the lines that do not match. Programmers often use this
command when they need to make program alterations instead of rewriting the entire source code.
The simplest form of this command is diff file1.ext file2.ext
chmod is another Linux command, used to change the read, write, and execute permissions
of files and directories. As this command is rather complicated, you can read the full
tutorial in order to execute it properly.
Confused about the function of certain Linux commands? Don’t worry, you can easily learn
how to use them right from Linux’s shell by using the man command. For instance,
entering man tail will show the manual instruction of the tail command.
14. WC command
The wc command in UNIX is a command line utility for printing newline, word and byte
counts for files. It can return the number of lines in a file, the number of characters in a file and
the number of words in a file. It can also be combine with pipes for general counting operations.
15. wildcards
A wildcard in Linux means it might be a symbol or set of symbols representing other characters.
It is generally used in substituting any string or a character. Wildcards are mainly used to
increase the efficiency and flexibility of searches in Linux.
1. ps command
ps command is short for ‘Process Status’. It displays the currently-running processes. However,
unlike the top command, the output generated is not in realtime.
PID process ID
2.Kill command
There are different types of signals that you can send. However, the most common one is ‘kill -9’
which is ‘SIGKILL‘.
$ kill –L
3. sleep command
sleep command is used to create a dummy job. A dummy job helps in delaying the execution.
It takes time in seconds by default but a small suffix(s, m, h, d) can be added at the end to
convert it into any other format. This command pauses the execution for an amount of time
which is defined by NUMBER.
Syntax:
sleep NUMBER[SUFFIX]...
Example:
4. Batch command
batch command is used to read commands from standard input or a specified file and execute
them when system load levels permit.
5. at command