OS Structures and Processes - Operating Systems | CMPSCI 377, Study notes of Operating Systems

Material Type: Notes; Professor: Berger; Class: Operating Systems; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Fall 2005;

Typology: Study notes

Pre 2010

Uploaded on 08/18/2009

koofers-user-t59
koofers-user-t59 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPSCI 377 Operating Systems Fall 2005
Lecture 4: September 22
Lecturer: Emery Berger Scribe: Andrey Ostapchenko and Nikita Ivanov
Today:
OS Structures and Processes
4.1 Processes
OS executes variety of programs:
Batch System jobs: run one after the other
Time-Shared systems: user programs or tasks
Definition 4.1 A process is a fundamental schedulable unit of execution
At minimum, each process includes:
Program counter (stack location)
Stack (variable values)
Data section (global variables, address space)
Process states:
New: being created, i.e. process goes into memory from the disk
Running: instructions being executed
Waiting: waiting for some event to occur, i.e. awaiting data from disk
Ready: waiting to be assigned to a processor
Terminated: self-explanatory
Zombie: useless children processes spawned by a parent process that has crashed
Processes usually loop between 3 states - running, waiting, ready. Transitions from one state to another
usually happen on program actions, OS actions, or interrupts
As an example, in UNIX a user can choose to run the process and wait until it finishes, or run it in background:
Sequential run: cp -r foo /bar
That will recursively copy foo into bar and then prompt for another command.
Background run: cp -r foo /bar &
That will run the same process, but user will be able to continue working while the process is running.
4-1
pf3

Partial preview of the text

Download OS Structures and Processes - Operating Systems | CMPSCI 377 and more Study notes Operating Systems in PDF only on Docsity!

CMPSCI 377 Operating Systems Fall 2005

Lecture 4: September 22

Lecturer: Emery Berger Scribe: Andrey Ostapchenko and Nikita Ivanov

Today:

  • OS Structures and Processes

4.1 Processes

OS executes variety of programs:

Batch System jobs: run one after the other Time-Shared systems: user programs or tasks

Definition 4.1 A process is a fundamental schedulable unit of execution

At minimum, each process includes:

  • Program counter (stack location)
  • Stack (variable values)
  • Data section (global variables, address space)

Process states:

New: being created, i.e. process goes into memory from the disk Running: instructions being executed Waiting: waiting for some event to occur, i.e. awaiting data from disk Ready: waiting to be assigned to a processor Terminated: self-explanatory Zombie: useless children processes spawned by a parent process that has crashed

Processes usually loop between 3 states - running, waiting, ready. Transitions from one state to another usually happen on program actions, OS actions, or interrupts

As an example, in UNIX a user can choose to run the process and wait until it finishes, or run it in background: Sequential run: cp -r foo /bar That will recursively copy foo into bar and then prompt for another command. Background run: cp -r foo /bar & That will run the same process, but user will be able to continue working while the process is running.

4-2 Lecture 4: September 22

4.1.1 Process Control Block

Definition 4.2 AProcess Control Block or PCB tracks process state, such as program counter, cpu registers, I/O status, memory-management

As an example of a poorly designed PCB, consider the following: in Linux, process identifiers are limited to

  1. If the number of processes increases past that number, the operating system will crash.

Note that it is expensive to switch between processes. When a user switches from one process to another: TLB needs to be flushed and repopulated Memory cache is useless (”cold”), so it needs to be renewed.

The OS usually tries to solve this problem by scheduling each process to run for a specific period of time. This job is handled by the scheduler using queues. Scheduler queues:

Job queue: the set of all processes in a system Ready queue: set of processes residing in main memory ready and waiting to be executed Device queue: set of processes waiting for I/O device - one per device

These queues are simple linked lists. Same item can be placed on more than one queue at the same time.

4.2 Forking

It is possible for one process to create another process - this is called forking. The creator is called the parent process and the new processes are called children processes. A parent process can wait for the children processes to complete or it can continue running in parallel.

UNIX: f ork() copies variables/registers from parent to child. Memory lazily copied - copy-on-write (by reference) The only difference between parent and child is the return value - parent returns pid (process ID) of child; child returns 0.

On termination of a process the operating system reclaims all resources.

UNIX processes have the ability to terminate themselves via the exit system call; they can also terminate child processes via the kill system call.

Processes can also cooperate and work together on a task. This may improve performance and yield possible simpler program design.