Introduction to Operating Systems and Programming Languages
Software and Its Types
Software Features
- Intangible
- No deterioration or destruction
- Developed through a process
- Multiple copies with potential for bugs across all copies
System Software
System software consists of programs and applications that manage hardware components and lack a specific user-facing purpose. This layer abstracts away the complexities of direct hardware interaction.
Application Software
Application software comprises programs designed for specific user tasks, such as word processors.
Operating Systems (OS)
The OS is a program that facilitates communication between users and the computer system. It provides a platform for running application programs and performs the following tasks:
- Restricts direct user and program manipulation of hardware components.
- Offers a user interface for seamless computer interaction.
- Manages hardware devices, acting as an intermediary between users/programs and the hardware.
- Organizes and manages the system’s disk, including file and folder management.
- Efficiently manages the processor and main memory.
- Handles user account management.
Interactive Processes and Multiprocessing
Interactive Processes
In interactive processes, the time spent on input/output operations is significantly larger than processor usage time due to the high speed of processors. The OS leverages this to manage processor usage efficiently.
Multiprocessing
Even with a single processor (uniprocessor), multiple processes can run concurrently (multiprocessing). A uniprocessor system can support multiple users with their respective processes running simultaneously. Multi-processor systems, like supercomputers, can handle numerous processes on each processor, enabling them to serve thousands of users quickly.
Process and Memory Management
Process
The OS addresses the challenge of sharing CPU time among multiple processes by allocating time slices (quanta) to each process. If a process completes its quantum and no other process is waiting, it continues to use the CPU for another quantum. The OS also manages memory allocation for all running processes using mechanisms like:
- Memory Compaction: Rearranges memory to create larger contiguous blocks.
- Segmentation: Divides a program into logical segments, loading and unloading them as needed.
- Paging: Divides main memory into fixed-size pages and swaps inactive pages to virtual memory.
Segmentation and paging utilize virtual memory. Segmentation involves dividing a program into logical parts (segments). When a segment finishes execution, it’s swapped out for another. Paging divides main memory into equal-sized portions (pages), moving inactive pages to virtual memory. The OS manages the exchange of pages between main memory and virtual memory. Segmentation was typically determined by the programmer, while paging is managed by the OS. Combining both techniques (paged segmentation) can leverage the advantages of each.
Programming Languages
Low-Level Languages
A programming language is a set of symbols and rules used to write instructions. Processors understand only machine instructions, represented by sequences of zeros and ones. Assembly languages replace opcodes with mnemonics, making code slightly more readable. Each assembly instruction corresponds to a machine code instruction, except for macros (sets of instructions referenced by a label). Assembly language reduces the complexity of machine code but still requires translation to machine code for execution.
High-Level Languages
High-level programming languages use syntax closer to natural language, enhancing readability and reducing errors. They work with variables instead of memory addresses and have a rigid syntax and lexicon. FORTRAN was one of the first high-level languages, designed for complex formulas. Numerous languages have evolved since then. High-level languages aim for platform independence, allowing programs to run on any computer regardless of its machine language. They require a translator (compiler or interpreter) to convert the code into machine code.
Translators: Interpreters and Compilers
Every high-level language instruction translates to a set of machine code instructions. The translation process involves lexical analysis, syntactic analysis, semantic analysis, and code generation. There are two main types of translators:
Interpreters
- Analyze and translate instructions one at a time.
- Execute each instruction immediately after translation.
- Stop upon encountering a fatal error.
- Do not save the translated version of the program.
- Require re-translation each time the program runs.
Compilers
- Perform the entire analysis process first.
- List errors and stop translation if errors are found.
- Generate a complete machine code program and store a copy if no errors are found.
- Do not execute the program, only analyze and translate.
- Require translation only once, after which the program can be executed multiple times.
Hybrid Interpreters
- Aim to run on different machines using an “intermediate” code that has been pre-compiled.
- The compiled program can be distributed and then interpreted on different machines with different machine languages.
- Java utilizes this approach for internet applications.
Comparison between Compilers and Interpreters
- Interpreters were initially more common, but compilers are now more prevalent.
- Compilers translate once, allowing multiple executions, while interpreters require translation for each execution.
- Compiler-translated programs execute faster and require less memory.
- Interpreters offer more accurate error detection and diagnosis.
- Interpreters enable platform independence for programs.