System Programming can be defined as the act of building Systems Software
using System Programming Languages. According to Computer Hierarchy, one
which comes at last is Hardware. Then it is Operating System, System
Programs, and finally Application Programs. Program Development and
Execution can be done conveniently in System Programs. Some of the System
Programs are simply user interfaces, others are complex. It traditionally lies
between the user interface and system calls.
In the context of an operating system, system programs are nothing but a
special software which give us facility to manage and control the computer’s
hardware and resources. As we have mentioned earlier these programs are
more closely with the operating system so it executes the operation fast and
helpful in performing essential operation which can’t be handled by application
software .
Note : The user can only view up-to-the System Programs he can’t see System
Calls.
Here are the examples of System Programs :
1. File Management – A file is a collection of specific information stored
in the memory of a computer system. File management is defined as
the process of manipulating files in the computer system, its
management includes the process of creating, modifying and deleting
files.
2. Command Line Interface(CLI’s) : CLIs is the essential tool for user . It
provide user facility to write commands directly to the system for
performing any operation . It is a text-based way to interact with
operating system. CLIs can perform many tasks like file
manipulation,system configuration and etc.
3. Device drivers :Device drivers work as a simple translator for OS and
devices . Basically it act as an intermediatry between the OS and
devices and provide facility to both OS and devices to understand each
other’s language so that they can work together efficiently without
interrupt.
4. Status Information – Information like date, time amount of available
memory, or disk space is asked by some users. Others providing
detailed performance, logging, and debugging information which is
more complex. All this information is formatted and displayed on
output devices or printed. Terminal or other output devices or files or a
window of GUI is used for showing the output of programs.
5. File Modification – For modifying the contents of files we use this. For
Files stored on disks or other storage devices, we used different types
of editors. For searching contents of files or perform transformations of
files we use special commands.
6. Programming-Language support – For common programming
languages, we use Compilers, Assemblers, Debuggers, and
interpreters which are already provided to users. It provides all support
to users. We can run any programming language. All languages of
importance are already provided.
7. Program Loading and Execution – When the program is ready after
Assembling and compilation, it must be loaded into memory for
execution. A loader is part of an operating system that is responsible
for loading programs and libraries. It is one of the essential stages for
starting a program. Loaders, relocatable loaders, linkage editors, and
Overlay loaders are provided by the system.
8. Communications 𠄺l connections among processes, users, and
computer systems are provided by programs. Users can send
messages to another user on their screen, User can send e-mail,
browsing on web pages, remote login, the transformation of files from
one user to another.
System protection in an operating system refers to the mechanisms
implemented by the operating system to ensure the security and integrity of the
system. System protection involves various techniques to prevent unauthorized
access, misuse, or modification of the operating system and its resources.
There are several ways in which an operating system can provide system
protection:
User authentication: The operating system requires users to authenticate
themselves before accessing the system. Usernames and passwords are
commonly used for this purpose.
Access control: The operating system uses access control lists (ACLs) to
determine which users or processes have permission to access specific
resources or perform specific actions.
Encryption: The operating system can use encryption to protect sensitive data
and prevent unauthorized access.
Firewall: A firewall is a software program that monitors and controls incoming
and outgoing network traffic based on predefined security rules.
Antivirus software: Antivirus software is used to protect the system from
viruses, malware, and other malicious software.
System updates and patches: The operating system must be kept up-to-date
with the latest security patches and updates to prevent known vulnerabilities
from being exploited.
By implementing these protection mechanisms, the operating system can
prevent unauthorized access to the system, protect sensitive data, and ensure
the overall security and integrity of the system.
What is Protection?
Protection refers to a mechanism which controls the access of programs,
processes, or users to the resources defined by a computer system. We can take
protection as a helper to multi programming operating system, so that many
users might safely share a common logical name space such as directory or files.
Need for Protection:
● To prevent the access of unauthorized users
● To ensure that each active programs or processes in the system uses
resources only as the stated policy
● To improve reliability by detecting latent errors
Role of Protection:
The role of protection is to provide a mechanism that implement policies which
defines the uses of resources in the computer system. Some policies are defined
at the time of design of the system, some are designed by management of the
system and some are defined by the users of the system to protect their own
files and programs. Every application has different policies for use of the
resources and they may change over time so protection of the system is not only
concern of the designer of the operating system. Application programmer
should also design the protection mechanism to protect their system against
misuse. Policy is different from mechanism. Mechanisms determine how
something will be done and policies determine what will be done. Policies are
changed over time and place to place. Separation of mechanism and policy is
important for the flexibility of the system.
Advantages of system protection in an operating system:
1. Ensures the security and integrity of the system
2. Prevents unauthorized access, misuse, or modification of the operating
system and its resources
3. Protects sensitive data
4. Provides a secure environment for users and applications
5. Prevents malware and other security threats from infecting the system
6. Allows for safe sharing of resources and data among users and
applications
7. Helps maintain compliance with security regulations and standards
Disadvantages of system protection in an operating system:
1. Can be complex and difficult to implement and manage
2. May slow down system performance due to increased security
measures
3. Can cause compatibility issues with some applications or hardware
4. Can create a false sense of security if users are not properly educated
on safe computing practices
5. Can create additional costs for implementing and maintaining security
measures.
A file system is a method an operating system uses to store, organize, and
manage files and directories on a storage device. Some common types of file
systems include:
1. FAT (File Allocation Table): An older file system used by older
versions of Windows and other operating systems.
2. NTFS (New Technology File System): A modern file system used by
Windows. It supports features such as file and folder permissions,
compression, and encryption.
3. ext (Extended File System): A file system commonly used on Linux
and Unix-based operating systems.
4. HFS (Hierarchical File System): A file system used by macOS.
5. APFS (Apple File System): A new file system introduced by Apple for
their Macs and iOS devices.
The advantages of using a file system
1. Organization: A file system allows files to be organized into directories
and subdirectories, making it easier to manage and locate files.
2. Data protection: File systems often include features such as file and
folder permissions, backup and restore, and error detection and
correction, to protect data from loss or corruption.
3. Improved performance: A well-designed file system can improve the
performance of reading and writing data by organizing it efficiently on
disk.
Disadvantages of using a file system
1. Compatibility issues: Different file systems may not be compatible
with each other, making it difficult to transfer data between different
operating systems.
2. Disk space overhead: File systems may use some disk space to store
metadata and other overhead information, reducing the amount of
space available for user data.
3. Vulnerability: File systems can be vulnerable to data corruption,
malware, and other security threats, which can compromise the
stability and security of the system.
A file is a collection of related information that is recorded on secondary storage.
Or file is a collection of logically related entities. From the user’s perspective, a
file is the smallest allotment of logical secondary storage.
The name of the file is divided into two parts as shown below:
● name
● extension, separated by a period.
The Following Issues Are Handled By The File Syst4em
We’ve seen a variety of data structures where the file could be kept. The file
system‘s job is to keep the files organized in the best way possible.
A free space is created on the hard drive whenever a file is deleted from it. To
reallocate them to other files, many of these spaces may need to be recovered.
Choosing where to store the files on the hard disc is the main issue with files
one block may or may not be used to store a file. It may be kept in the disk’s
non-contiguous blocks. We must keep track of all the blocks where the files are
partially located.
Files Attributes And Their Operations
Attributes Types Operations
Name Doc Create
Type Exe Open
Size Jpg Read
Creation Data Xis Write
Author C Append
Last Modified Java Truncate
protection class Delete
Close
Usual
File type Function
extension
Read to run machine language
Executable exe, com, bin
program
Object obj, o Compiled, machine language not linked
C, java, pas,
Source Code Source code in various languages
asm, a
Batch bat, sh Commands to the command interpreter
Text txt, doc Textual data, documents
Word
wp, tex, rrf, doc Various word processor formats
Processor
Related files grouped into one
Archive arc, zip, tar
compressed file
Multimedia mpeg, mov, rm For containing audio/video information
Markup xml, html, tex It is the textual data and documents
It contains libraries of routines for
Library lib, a ,so, dll
programmers
It is a format for printing or viewing an
Print or View gif, pdf, jpg
ASCII or binary file.
FILE DIRECTORIES
The collection of files is a file directory. The directory contains information about
the files, including attributes, location, and ownership. Much of this information,
especially that is concerned with storage, is managed by the operating system.
The directory is itself a file, accessible by various file management routines.
Information contained in a device directory is:
● Name
● Type
● Address
● Current length
● Maximum length
● Date last accessed
● Date last updated
● Owner id
● Protection information
The operation performed on the directory are:
● Search for a file
● Create a file
● Delete a file
● List a directory
● Rename a file
● Traverse the file system
The advantages of maintaining directories are:
● Efficiency: A file can be located more quickly.
● Naming: It becomes convenient for users as two users can have same
name for different files or may have different name for same file.
● Grouping: Logical grouping of files can be done by properties e.g. all
java programs, all games etc.
SINGLE-LEVEL DIRECTORY
In this, a single directory is maintained for all the users.
● Naming problem: Users cannot have the same name for two files.
● Grouping problem: Users cannot group files according to their needs.
TWO-LEVEL DIRECTORY
In this separate directories for each user is maintained.
● Path name: Due to two levels there is a path name for every file to
locate that file.
● Now, we can have the same file name for different users.
● Searching is efficient in this method.
TREE-STRUCTURED DIRECTORY
The directory is maintained in the form of a tree. Searching is efficient and also
there is grouping capability. We have absolute or relative path name for a file.
FILE ALLOCATION METHODS
Continuous Allocation
A single continuous set of blocks is allocated to a file at the time of file creation.
Thus, this is a pre-allocation strategy, using variable size portions. The file
allocation table needs just a single entry for each file, showing the starting block
and the length of the file. This method is best from the point of view of the
individual sequential file. Multiple blocks can be read in at a time to improve I/O
performance for sequential processing. It is also easy to retrieve a single block.
For example, if a file starts at block b, and the ith block of the file is wanted, its
location on secondary storage is simply b+i-1.
Disadvantage
● External fragmentation will occur, making it difficult to find contiguous
blocks of space of sufficient length. A compaction algorithm will be
necessary to free up additional space on the disk.
● Also, with pre-allocation, it is necessary to declare the size of the file at
the time of creation.
Linked Allocation(Non-contiguous allocation)
Allocation is on an individual block basis. Each block contains a pointer to the
next block in the chain. Again the file table needs just a single entry for each file,
showing the starting block and the length of the file. Although pre-allocation is
possible, it is more common simply to allocate blocks as needed. Any free block
can be added to the chain. The blocks need not be continuous. An increase in file
size is always possible if a free disk block is available. There is no external
fragmentation because only one block at a time is needed but there can be
internal fragmentation but it exists only in the last disk block of the file.
Disadvantage
● Internal fragmentation exists in the last disk block of the file.
● There is an overhead of maintaining the pointer in every disk block.
● If the pointer of any disk block is lost, the file will be truncated.
● It supports only the sequential access of files.
Indexed Allocation
It addresses many of the problems of contiguous and chained allocation. In this
case, the file allocation table contains a separate one-level index for each file:
The index has one entry for each block allocated to the file. The allocation may
be on the basis of fixed-size blocks or variable-sized blocks. Allocation by blocks
eliminates external fragmentation, whereas allocation by variable-size blocks
improves locality. This allocation technique supports both sequential and direct
access to the file and thus is the most popular form of file allocation.
Disk Free Space Management
Just as the space that is allocated to files must be managed, so the space that is
not currently allocated to any file must be managed. To perform any of the file
allocation techniques, it is necessary to know what blocks on the disk are
available. Thus we need a disk allocation table in addition to a file allocation
table. The following are the approaches used for free space management.
1. Bit Tables: This method uses a vector containing one bit for each block
on the disk. Each entry for a 0 corresponds to a free block and each 1
corresponds to a block in use.
For example 00011010111100110001
In this vector every bit corresponds to a particular block and 0 implies
that that particular block is free and 1 implies that the block is already
occupied. A bit table has the advantage that it is relatively easy to find
one or a contiguous group of free blocks. Thus, a bit table works well
with any of the file allocation methods. Another advantage is that it is
as small as possible.
2. Free Block List: In this method, each block is assigned a number
sequentially and the list of the numbers of all free blocks is maintained
in a reserved block of the disk.
Traps and system calls are two mechanisms used by an operating system (OS)
to perform privileged operations and interact with user-level programs. Here is
an overview of each mechanism:
1. Traps: A trap is an interrupt generated by the CPU when a user-level
program attempts to execute a privileged instruction or encounters an
error. When a trap occurs, the CPU transfers control to the kernel and
executes a trap handler. The trap handler checks the type of trap and
takes appropriate action, such as terminating the program or
performing a privileged operation on behalf of the program.
2. System calls: A system call is a request made by a user-level program
to the OS to perform a privileged operation, such as reading from or
writing to a file or allocating memory. To make a system call, the
program executes a special instruction that triggers a software
interrupt. The OS then transfers control to the kernel and executes a
system call handler. The system call handler checks the type of system
call and takes appropriate action, such as reading from a file or
allocating memory.
3. Traps and system calls are similar in that they both involve transferring
control to the kernel to perform privileged operations. However, traps
are usually generated automatically by the CPU when a program
encounters an error or attempts to execute a privileged instruction,
while system calls are initiated by the program itself to request
privileged operations.
In summary, traps and system calls are essential mechanisms used by an
operating system to ensure that privileged operations are performed securely
and efficiently. Understanding how these mechanisms work is important for
developing operating systems and writing programs that interact with them.
On the off chance that Operating System (OS) is secured, how does the program
request administrations from OS? Client programs can’t call capacities inside the
working framework’s memory, since it can’t see those territories of memory.
An extraordinary client mode machine guidance, known as TRAP guidance,
causes an exemption, switches CPU mode to Kernel mode, and starts the
handler for TRAP guidance.
To request specific help from OS, the client program places esteem in machine
registers to show what administration it requires. At that point, it executes
TRAP guidance, which changes CPU mode to advantaged mode and moves
execution to the TRAP handler in OS’s memory.
OS checks solicitation, and performs it, utilizing the dispatch table to pass
control to one of a lot of OS administration schedules. At the point when the
administration has been played out, OS returns control to the program, bringing
down benefits back to client mode. Hence, activity-just approaches favored OS
through solitary, all-around ensured section points. This component for
acquiring OS administrations is known as System Call. The arrangement of
accessible framework calls is known as the Operating System’s Application
Program Interface or API.
In many operating systems, the fork system call is an essential operation. The
fork system call allows the creation of a new process. When a process calls the
fork(), it duplicates itself, resulting in two processes running at the same time.
The new process that is created is called a child process. It is a copy of the
parent process. The fork system call is required for process creation and enables
many important features such as parallel processing, multitasking, and the
creation of complex process hierarchies.
It develops an entirely new process with a distinct execution setting. The new
process has its own address space, and memory, and is a perfect duplicate of
the caller process.
Basic Terminologies Used in Fork System Call in
Operating System
● Process: In an operating system, a process is an instance of a program
that is currently running. It is a separate entity with its own memory,
resources, CPU, I/O hardware, and files.
● Parent Process: The process that uses the fork system call to start a
new child process is referred to as the parent process. It acts as the
parent process’s beginning point and can go on running after the fork.
● Child Process: The newly generated process as a consequence of the
fork system call is referred to as the child process. It has its own
distinct process ID (PID), and memory, and is a duplicate of the parent
process.
● Process ID: A process ID (PID) is a special identification that the
operating system assigns to each process.
● Copy-on-Write: The fork system call makes use of the memory
management strategy known as copy-on-write. Until one of them
makes changes to the shared memory, it enables the parent and child
processes to share the same physical memory. To preserve data
integrity, a second copy is then made.
● Return Value: The fork system call’s return value gives both the parent
and child process information. It assists in handling mistakes during
process formation and determining the execution route.
Process Creation
When the fork system call is used, the operating system completely copies the
parent process to produce a new child process. The memory, open file
descriptors, and other pertinent properties of the parent process are passed
down to the child process. The child process, however, has a unique execution
route and PID.
The copy-on-write method is used by the fork system call to maximize memory
use. At first, the physical memory pages used by the parent and child processes
are the same. To avoid unintentional changes, a separate copy is made
whenever either process alters a shared memory page.
The return value of the fork call can be used by the parent to determine the
execution path of the child process. If it returns 0 then it is executing the child
process, if it returns -1 then there is some error; and if it returns some positive
value, then it is the PID of the child process.
Fork() System call
Advantages of Fork System Call
● Creating new processes with the fork system call facilitates the
running of several tasks concurrently within an operating system. The
system’s efficiency and multitasking skills are improved by this
concurrency.
● Code reuse: The child process inherits an exact duplicate of the parent
process, including every code segment, when the fork system call is
used. By using existing code, this feature encourages code reuse and
streamlines the creation of complicated programmes.
● Memory Optimisation: When using the fork system call, the
copy-on-write method optimises the use of memory. Initial memory
overhead is minimised since parent and child processes share the same
physical memory pages. Only when a process changes a shared
memory page, improving memory efficiency, does copying take place.
● Process isolation is achieved by giving each process started by the fork
system call its own memory area and set of resources. System stability
and security are improved because of this isolation, which prevents
processes from interfering with one another.
Disadvantages of Fork System Call
● Memory Overhead: The fork system call has memory overhead even
with the copy-on-write optimisation. The parent process is first copied
in its entirety, including all of its memory, which increases memory use.
● Duplication of Resources: When a process forks, the child process
duplicates all open file descriptors, network connections, and other
resources. This duplication may waste resources and perhaps result in
inefficiencies.
● Communication complexity: The fork system call generates
independent processes that can need to coordinate and communicate
with one another. To enable data transmission across processes,
interprocess communication methods, such as pipes or shared memory,
must be built, which might add complexity.
● Impact on System Performance: Forking a process duplicates memory
allocation, resource management, and other system tasks. Performance
of the system may be affected by this, particularly in situations where
processes are often started and stopped.