Skip to content

Instantly share code, notes, and snippets.

@shardulbee
Last active February 16, 2018 00:37
Show Gist options
  • Save shardulbee/9b17bfa2a2fcab4987ea4c0a07927654 to your computer and use it in GitHub Desktop.
Save shardulbee/9b17bfa2a2fcab4987ea4c0a07927654 to your computer and use it in GitHub Desktop.

Processes

  • abstraction of running program
  • supports ability to have psuedo-concurrent operation
    • In a uniprogramming model, no notion of a process is needed, because you only have one at all times

Key elements of a process

  • program counter
  • registers
  • input data
  • program

Process Management Issues

  • lifecycle management - how to create processes, manage state changes and reasons for those state chages, how to terminate processes
  • precedence management - how to give priority to one process over another

What is a process? Representation

  • Process Control Block (PCB) contains all the necessary information
    • id
    • state vector -- all the information necessary to run the process
    • status (killed, blocked, etc)
    • creation tree (whats this?)
    • priorty
    • other metadata

Process Creation

4 types of events will create processes

  1. system initialization
  2. execution of process creation syscall
  3. user request to create a new process
  4. initiation of a batch job

Two approaches, which are build one from scratch (windows) or clone an existing one (unix)

Cloning a process

  1. stop the current process and save its state
  2. make a copy of code, data, heap, and PCB
  3. make process known to process scheduler
  • In unix, fork() syscall is used to create
  • creates an identical copy of the calling process (file descriptors, variables, etc.)
  • after fork(), parent continues running concurrently with child, competing for cpu
  • every fork() call returns twice -- exponential growth

Process I/O

  • handles to i/o objects are called file descriptors (fd(s))
  • fds are stored in an array structure by the kernel on a per process level
  • can only access these through syscalls
  • fds 0, 1, 2 corresponding to stdin, stdout, and stderr are created for each new process
  • can have multiple entries in the fd table point to the same resource

Memory

  • from a process view, memory is a large array (logical view of memory). OS manages the physical view.

    • kernel takes up some of this memory, and the rest is "logically" for the process
    • does this mean that there is no cap on how much memory a process can use? yes! Look at Google chrome, for example
  • instead of sharing the memory space (can lead to some problems with data corruption/security), give them an address space (addressable memory)

    • this is all the addresses it could generate (write to?)
    • some of it is taken by the kernel, ie, persistent address space, shared by all processes
  • since the kernel space is shared, one process could communicate to other processes

    • through shared memory in kernel space ie) ask the kernel, please store this data and allow it to be read by some other process
    • through message passing ie) ask the kernel, please take this data and pass it to another process as input (pipe syscall)
  • address space switching

    • every time there is a process switch, address space switches so that the process has its own view into the memory

Threads

  • What is the key difference between concurrency and parallelism?

    • paralellism is doing more than 1 task simultaneously
    • concurrency supports more than one task making progress
  • parallelism is good when you want to do something quicker, need to do a piece of work that doesn't depend on other things

    • question becomes: how fast can we go?
  • applications have a serial and parallel portion

Amdahl's Law states that performance improvement obtained by applying an enhancement on an application execution is limited by the fraction of the time enhancement can be applied.

  • compute the speedup obtainable by adding N cores to an application. Let S be the serial portion and 1-S be the parallel portion.
speedup <= 1/(S + (1-S)/n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment