03

Processes Overview

  • Chapters 3-6 in CS 4410 Operating Systems by R. Agarwal et al. discuss processes in operating systems.

Definitions

  • Program: Contains code and data specified in a programming language, typically stored in a file on disk.

  • Process: Occurs when a program is run; it is an instance of a program in execution, and multiple processes of the same program can run concurrently.

Executables

  • An executable is a file with:

    • CPU instructions (executable code)

    • Data manipulated by these instructions

  • Created through the compilation of a program and linked with necessary libraries.

Process Abstraction

  • A process runs on:

    • Address Space: Memory and execution context (registers including Program Counter (PC) and Stack Pointer (SP))

    • Environment: Clocks, files, networks, manipulated through system calls.

    • Good abstractions should hide implementation details, provide easy interfaces, be instantiated multiple times, and be efficient.

Lifecycle of a Process vs Program

  • A program is passive (just code and data).

  • A process is active (it changes data, registers, files).

  • Same program can yield multiple processes (e.g., ./program &).

Process Memory Layout

  • Memory is organized in segments:

    • Text Segment: Holds executable code and constants.

    • Data Segment: Contains global variables.

    • Heap: Used for dynamic memory allocation.

    • Stack: Used for function calls and local variables.

Process Stack and Heap

  • Stack: Manages function calls, maintains local variables, return addresses, and temporary data.

  • Heap: Used with functions related to dynamic memory allocation to manage memory.

System Calls

  • Processes interact with the OS kernel through system calls to perform tasks such as reading input, writing to screens, creating processes, and managing files.

  • System calls have a skinny interface which enhances portability and security.

Process Creation

  • In UNIX, process creation involves:

    • fork(): Creates a new child process that is a clone of the parent process.

    • exec(): Loads a new program into the address space of a process.

  • Process control block (PCB) contains information such as process ID, user ID, and the current state of the process.

Threading

  • Threads are lightweight processes that share the same memory space and can run concurrently.

  • Two types of threads:

    • Kernel Threads: Managed by the operating system; can block calls.

    • User Threads: Managed entirely in user space, require less overhead during context switching.

Thread Management API
  • Example functions for thread management include:

    • thread_create(func, arg): Creates a new thread.

    • thread_yield(): Yields execution of the CPU to allow other threads to run.

    • thread_exit(): Finishes the execution of the thread.

Shell Interface

  • A shell is an interpreter that allows users to create and manage processes through executing commands.

  • Environment variables hold information about the process environment and include paths to executables and other system settings.

Understanding Processes and Threads

  • Processes represent an execution environment whereas threads represent separate execution paths within the same process's memory space.

  • Proper management of threads can provide advantages in responsiveness and resource sharing, important for applications such as web servers.

Communication and Control in Processes

  • Various system calls allow processes to communicate with the OS and manage their execution states, helping in creating more sophisticated and responsive applications.

robot