Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

Chap 2 System Structures.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
The Process Model.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
System Calls 1.
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Introduction to Processes CS Intoduction to Operating Systems.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
Chapter 2: Operating-System Structures. 2.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 2: Operating-System Structures Operating.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Silberschatz, Galvin and Gagne  Operating System Concepts Process Concept An operating system executes a variety of programs:  Batch system.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 2: Operating-System Structures.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Protection of System Resources
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Chapter 3: Processes.
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Operating Systems Lecture 6.
Process & its States Lecture 5.
Chapter 3: Processes.
Tutorial: The Programming Interface
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Presentation transcript:

Process

Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program counter – stack – data section Process life-cycle

Process =? Program More to a process than just a program: – Program is static, with the potential for exection – process is a program in execution and have a state – One program can be executed several times and thus has several processes main () { …; } A() { … } main () { …; } A() { … } Heap Stack A main Program Process

Process Description: Process Control Block (PCB) Information associated with each process – Process state – Program counter – CPU registers – CPU scheduling information – Memory-management information – Accounting information – I/O status information A process is named using its process ID (PID) Data is stored in a process control block (PCB)

Ready Queue And Various I/O Device Queues

CPU Switch From Process to Process

Process Creation A process is created by another process, which, in turn create other processes, forming a tree of processes Parent and child process In Linux, using “ps –f”, the PPID field is the parent The fist process is Init After creating a child, the parent may either wait for it to finish or continue currently Some system, the children inherit the privileges of the parents Unix: children of the shell inherit the Process User ID and thus execute with the user’s privileges

Linux Process Tree

Unix Process: ps -f

Process Creation Address space – Child duplicate of parent – Child has a program loaded into it UNIX examples – The fork() system call in Unix creates a new process. After a successful fork() call, two copies of the original code will be running. In the original process (the parent) the return value of fork() will be the process ID of the child. In the new child process the return value of fork() will be 0 – exec system call used after a fork() to replace the process ’ memory space with a new program

Process Creation: Unix In Unix, processes are created using fork() Creates and initializes a PCB and creates a new address space Initializes the address space with a copy of the entire contents of the address space of the parent Initializes the kernel resources to point to the resources used by parent (e.g., open files) Places the PCB on the ready queue Fork returns twice: Returns the child’s PID to the parent, “0” to the child

Creating Processes in UNIX Every process in UNIX has a unique identifier PID. The UNIX ps command lists each process associated with the user executing the command Whenever a (parent) process calls a fork(), a child process is created with its own descriptor, including its own copies of the parent ’ s program text, data, and stack segments The child and parent processes execute in their own separate address spaces This means that even though they have access to the same information, when the child is created, both the child and its parent each reference its own copy of the information

Process Creation: Unix How do we actually start a new program? int exec(char *prog, char *argv[]) Stops the current process Loads the program “prog” into the process’ address space Initializes hardware context and args for the new program Places the PCB onto the ready queue

#include main() { int pid; int rv; pid=fork(); switch(pid){ case -1: printf("Error -- Something went wrong with fork()\n"); exit(1); // parent exits case 0: printf("CHILD: This is the child process!\n"); printf("CHILD: My PID is %d\n", getpid()); printf("CHILD: My parent's PID is %d\n", getppid()); printf("CHILD: Enter my exit status: "); scanf(" %d", &rv); printf("CHILD: I'm outta here!\n"); exit(rv); default: printf("PARENT: This is the parent process!\n"); printf("PARENT: My PID is %d\n", getpid()); printf("PARENT: My child's PID is %d\n", pid); printf("PARENT: I'm now waiting for my child to exit()...\n"); wait(&rv); printf("PARENT: I'm outta here!\n"); }

#include main() { int pid; pid=fork(); switch(pid){ case -1: printf("Error -- Something went wrong with fork()\n"); exit(1); // parent exits case 0: execl("/bin/date","date",0); // this is the code the child runs default: wait(NULL); printf("PARENT: I'm outta here!\n"); }

System Calls

“system call” == “a function call that invokes the operating system services” These OS services typically written in a high-level language (C or C++), are isolated from the user programs. OS provides service to user program via system calls.

System Call Interface System calls Mostly accessed by programs via a high-level Application Program Interface (API) Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) Behind the scenes, functions that make up an API typically invoke system calls. Why would an application programmer prefer programming according to an API rather than invoking actual system calls?

System Calls vs. Library Routines A system call is just what its name implies – a request for the OS do something on behalf of the user’s program – E.g., read is a system call which asks the OS to fill a buffer with data stored on a disk drive (or other device). It would be chaotic if everyone were able to access devices whenever they pleased! A library routine does not usually need the OS to perform its work – E.g., the sin function, which computes the sine of an angle

Invoke the OS Hardware interrupt: Interrupts signal to the CPU that a hardware device has an event that needs attention, e.g. disk I/O complete, network packet arrived, keyboard input arrived, etc. Software trap: Interrupts also signal errors or requests for OS intervention (a system call), often called an “exception” or “trap” Explicit system call: application requests service

Example of System Calls

Suppose you have just compiled a program, producing, say for a Unix system, an executable file a.out. To run it, you type a.out – The shell reads the command you type – The shell then makes a system call, execve(),asking the OS to run a.out. The OS is now running – The OS looks in its disk directory, to determine where on disk the file a.out is – The OS checks its memory-allocation table (this is just an array in the OS) to find an unused region or regions of memory large enough for a.out as well as for stack space and the heap (used for calls to calloc() and malloc()) – The OS will then load a.out into those regions of memory, and will update its memory- allocation table accordingly – The OS will check a certain section of the a.out file, in which the linker previously recorded a.out's entry point, i.e. the instruction in a.out at which execution is to begin – The OS is now ready to initiate execution of a.out – The a.out program is now running!

System Call Implementation Typically, a number associated with each system call – System-call interface maintains a table indexed according to these numbers The system call interface invokes intended system call in OS kernel and returns status of the system call and any return values The caller need know nothing about how the system call is implemented – Just needs to obey API and understand what OS will do as a result call – Most details of OS interface hidden from programmer by API Managed by run-time support library (set of functions built into libraries included with compiler)

Standard C Library Example C program invoking printf() library call, which calls write() system call