Types of Files in Uni1
Types of Files in Uni1
In Unix operating system, all data is organized into files. Each file is organized into directories,
and these directories are organized in a tree-like structure called a file system.
1. Ordinary Files
Ordinary files are the files in Unix, which includes program instructions, text, and data.
Ordinary files are used to store our information like the text which we have to write or a picture
which we have to draw. This is the kind of the file which we mainly work with.
In the long-format output of ls -l, the "-" symbol is used to specified such kind of file.
2. Directory
Directory store both special as well as ordinary files. For the users who are familiar with Mac or
Windows operating systems, Unix directories are equivalent to the folders. A directory file
includes an entry file for each file and a subdirectory which it houses. If there are 5 files in a
directory, then there will be 5 entries in the directory. Every entry comprises of 2 components.
3. Special Files
We use special files to represent the real physical device like terminal, tape drive, and printer.
and also used for Input/Output(I/O) operations. Special files or devices are used for
Input/Output(I/O) on Linux and Unix systems. They look as similar to the ordinary file or
directory in a file system.
Mainly two kinds of special files for every device in the Unix system are there such as block
special files and character special files.
If we use the block special file for the device input/output (I/O), the data is moved to the higher
fixed-size blocks. This kind of access is known as block device access.
This is one character at a time for the terminal devices. However, for disk devices, raw access
means reading or writing across an entire section of data-blocks that are native to our disk.
In the long-format output of ls -l, using the "c" symbol character distinct, files are marked.
In the long-format output of ls -l, using the "b" symbol block, distinct files are marked.
4. Pipes
In Unix, with the help of pipes, we can link command together. Pipes is like a temporary file that
only exists to hold the data from one command till it is read by another. A one-way flow of data
is provided by the Unix pipe. The first command's output sequence is used like an input to the
next command sequence. In order to create a pipe, the vertical bar (|) has to be placed on the
command line between 2 commands. Such as who | wc -l
In the long-format output of ls -l, known as pipes, are marked using the symbol "p."
5. Sockets
Unix sockets are a type of file that enables for advanced inter-process communication. It is also
known as inter-process communication socket. In the framework of the client-server
application, a Unix Socket is used. It is essentially a data stream, same as the network stream
and network socket, except each transaction is local to the file system.
In the long-format output of ls -l, using the "s" symbol, Unix sockets are marked.
6. Symbolic Link
The symbolic link is used to reference another file in the file system. In order to reference
another file of the file system, we use the symbolic link. It involves a text representation of the
path to the file it refers to. To an end-user, a symbolic link will seem to have its own name, yet
when we need writing or reading data to this file, it will rather reference these tasks to the file it
focuses to. When we delete the soft link itself, then the data file would, in any case, be there.
The symbolic file will not function if the source file is deleted or moved to the different location.
In the case of the long-format output of ls -l, using the "l" symbol, the symbolic link is marked.
Here's a well-structured answer for each topic, designed to meet the *5-mark* requirement:
---
Process
A process is an active program i.e a program that is under execution. It is more than the
program code as it includes the program counter, process stack, registers, program code etc.
Compared to this, the program code is only the text section.
A process changes its state as it executes. This state partially depends on the current activity of
a process. The different states that a process is in during its execution are new, ready, running,
blocked, terminated.
A process control block is associated with each of the processes. It contains important
information about the process it is associated with such as process state, process number,
program counter, list of files and registers, CPU information, memory information etc.
Parent Process
All the processes in operating system are created when a process executes the fork() system call
except the startup process. The process that used the fork() system call is the parent process. In
other words, a parent process is one that creates a child process. A parent process may have
multiple child processes but a child process only one parent process.
On the success of a fork() system call, the PID of the child process is returned to the parent
process and 0 is returned to the child process. On the failure of a fork() system call, -1 is
returned to the parent process and a child process is not created.
Child Process
A child process is a process created by a parent process in operating system using a fork()
system call. A child process may also be called a subprocess or a subtask.
A child process is created as its parent process’s copy and inherits most of its attributes. If a
child process has no parent process, it was created directly by the kernel.
If a child process exits or is interrupted, then a SIGCHLD signal is send to the parent process.
- *Example:* echo $HOME displays /home/user. cd $HOME moves to the home directory.
---
An Inode is a data structure in UNIX operating system that contains important information
pertaining to files within a file system. When a file system is created in UNIX, a set amount of
indoes is created as well. Usually, about 1 percent of the file system disk space is allocated to
the inode table.
14 Bytes 2 Bytes
• A number of direct blocks (typically 12) that contains the first 12 blocks of the files.
• A single indirect pointer that points to a disk block which in turn is used as an index
block, if the file is too big to be indexed entirely by the direct blocks.
• A double indirect pointer that points to a disk block which is a collection of pointers to
disk blocks which are index blocks, used if the file is too big to beindexed by the direct
and single indirect blocks.
• A triple indirect pointer that points to an index block of index blocks of index blocks.
• Number of disk block address possible to store in 1 disk block = (Disk Block Size / Disk
Block Address).
• Small files need only direct blocks, so there is little waste in space or extra disk reads in
those cases. Medium-sized files may use indirect blocks. Only large files use double or
triple indirect blocks, which is reasonable since those files are large anyway. The disk is
now broken into two different types of blocks: Inode and Data Blocks.
• There must be some way to determine where the Inodes are, and to keep track of free
Inodes and disk blocks. This is done by a Superblock. Superblock is located at a fixed
position in the file system. The Superblock is usually replicated on the disk to avoid
catastrophic failure in case of corruption of the main Superblock.
• Index allocation schemes suffer from some of the same performance problems. As does
linked allocation. For example, the index blocks can be cached in memory, but the data
blocks may be spread all over a partition.
Inode Structure :
### 4. *Absolute Path Name*
An absolute path is a full path that specifies the location of a file or directory from the root
directory ('/'). It provides a complete address that points directly to a file or directory, regardless
of the current working directory. This path type always begins with the root directory, followed
by subdirectories, and ends with the desired file or directory name.
A relative path specifies the location of a file or directory in relation to the current working
directory (often abbreviated as pwd). It does not start with a slash ('/'), and it utilizes
navigational shortcuts to refer to the file or directory.
• Utilizes shortcuts like '.' (current directory) and '..' (parent directory) to navigate the
filesystem.
UNIX offers a shortcut in the relative pathname- that uses either the current or parent directory
as reference and specifies the path relative to it. A relative path-name uses one of these cryptic
symbols:
Now, what this actually means is that if we are currently in directory '/home/kt/abc' and now
you can use '..' as an argument to 'cd' to move to the parent directory /home/kt as :
$pwd
/home/kt/abc
$pwd
/home/kt
Note: Now '/ ' when used with '..' has a different meaning; instead of moving down a level, it
moves one level up:
$pwd
$cd ../..
$pwd
/home