TECHNOLOGY 

Published on
KembaraXtra-Case Law-Processes
What is a Process?
  • Definition: A process is a running instance of a program. It's the OS's way of executing a program.
  • Analogy: Think of a program as a recipe, and a process as someone actually following that recipe to bake a cake.
  • Location: Processes operate in user mode.
Key Components of a Process:
  • Container: A process acts as a container for a program's execution.
  • Private Virtual Memory Address Space: A dedicated memory space for the process (more on this later).
  • Program Code: A copy of the program's instructions loaded into the process's memory.
  • State Information: Data about the current status of the process.
Process Characteristics:
  • Multiple Instances: You can run the same program multiple times, creating a separate process for each instance.
  • Process ID (PID): A unique numerical identifier assigned to each process by the OS.
Process Relationships (Parent-Child):
  • Parent Process: The process that starts (creates) another process.
  • Child Process: The process created by a parent process.
  • Process Tree: The hierarchical relationship between processes, with parent processes branching out to child processes.
  • Orphan Process: A child process whose parent has terminated before the child.
    • Windows Behavior: The orphaned process remains parentless.
    • Linux Behavior: The init process (the first user-mode process) typically adopts the orphaned process.
Tools for Viewing Processes:
  • Linux:
    • pstree utility: Displays the process tree in a textual format.
      • Child threads shown with curly braces.
  • Windows:
    • Process Explorer (Microsoft): A GUI-based tool providing a comprehensive view of running processes.

KembaraXtra-Computer Science -Threads
1. Introduction to Threads
  • Default Program Execution: Programs typically execute instructions sequentially, handling one task at a time.
  • Need for Parallelism: Threads enable programs to perform multiple tasks concurrently (in parallel). Example: A program performing a long calculation while simultaneously updating the user interface (e.g., a progress bar).
  • Definition of a Thread: A thread is a schedulable unit of execution within a process, allowing for parallel execution of tasks. It can execute any program code loaded within that process.
2. Thread Characteristics
  • Task Focus: The code run by a thread typically encompasses a specific task the program aims to accomplish.
  • Shared Resources: Threads within a process share the same address space, code, and other resources.
  • Thread Creation: A process starts with one thread and can create additional threads as needed for parallel task handling.
  • Thread ID (TID): Each thread has a unique identifier.
3. Threads in Windows vs. Linux
  • Windows: Threads and processes are distinct object types. A process acts as a container for threads.
  • Linux: Both processes and threads are represented using a single data type. A group of threads sharing an address space and a common process identifier is considered a process. There is no separate process type.
4. Linux Thread and Process Identifiers
  • User Mode: Processes have a Process ID (PID), and threads have a Thread ID (TID).
  • Kernel Mode: The Linux kernel refers to a thread's ID as a PID and a process's ID as a thread group identifier (TGID).
5. Parallel Execution
  • The Illusion of Parallelism: Although threads are said to run in parallel, the actual simultaneous execution depends on the number of processor cores.
  • Processor Cores: Each processor core can execute only one thread at a time. The number of cores determines how many threads can run concurrently.
6. Physical vs. Logical Cores
  • Physical Core: A hardware implementation of a core within a CPU.
  • Logical Core: The ability of a single physical core to run multiple threads simultaneously (one thread per logical core). Intel's hyper-threading is an example. Logical cores do not achieve the full parallelism of physical cores.
7. The Role of the Operating System Scheduler
  • Scheduling: The operating system uses a scheduler, a software component, to manage thread execution.
  • Time Allocation: The scheduler allocates short periods of time (quantum) for each thread to run before suspending it to allow other threads to execute.
  • Transparency: This scheduling process is mostly hidden from the thread's code, giving the illusion of continuous parallel execution.
  • Developer Perspective: Developers write multithreaded applications as if all threads are running continuously in parallel.
Picture
0 Comments