Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.

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

CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Objectives Understand Process concept Process scheduling Creating.
Processes CSCI 444/544 Operating Systems Fall 2008.
1/27/2010CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying an earlier version.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
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.
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Process Concept An operating system executes a variety of programs
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
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.
Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication in Client-Server.
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Operating Systems Chapter 2
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Processes: program + execution state
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.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Processes. Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication.
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.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
H.-H. S. Lee 1 ECE3055 Computer Architecture and Operating Systems Lecture 10 Process, Thread Prof. Hsien-Hsin Sean Lee School of Electrical and Computer.
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.
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
3.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Overview: Process Concept Process Scheduling Operations on Processes.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
CSC 660: Advanced Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
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.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Chapter 3: Processes.
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Lecture 4 Process, Thread and Task
Process Management Presented By Aditya Gupta Assistant Professor
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 3: Processes.
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
Lecture 2: Processes Part 1
Operating Systems Lecture 6.
Process & its States Lecture 5.
Chapter 3: Processes.
Operating System Concepts
Chapter 3: Processes.
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Presentation transcript:

Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park

Computer Engineering Research Laboratory vi fork.c 2

Computer Engineering Research Laboratory 3

4GB 3GB Stack text data heap

Computer Engineering Research Laboratory 6 Process Concept  An operating system executes a variety of programs:  Batch system – jobs  Time-shared systems – user programs or tasks  Process – a program in execution; process execution must progress in sequential fashion  A process includes:  program counter  stack  data section

7 Process in Memory Stack Heap BSS Data Text SP PC

Virtualization 8 Processes are provided with 2 virtualizations: Virtualized Processor Virtualized Memory

Computer Engineering Research Laboratory 9 Process State  As a process executes, it changes state  new: The process is being created  running: Instructions are being executed  waiting: The process is waiting for some event to occur  ready: The process is waiting to be assigned to a process  terminated: The process has finished execution

Computer Engineering Research Laboratory 10 Diagram of Process State terminated running ready new admitted waiting interrupt scheduler dispatch I/O or event waitI/O or event completion exit

Computer Engineering Research Laboratory 11 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

12 Process management Registers Program counter Program status word Stack pointer Process state Time when process started CPU time used Children ’ s CPU time Time of next alarm Message queue pointers Pending signal bits Process id Various flag bits Memory management Pointer to text segment Pointer to data segment Pointer to bss segment Exit status Signal status Process id Parent process Process group Real uid Effective Real gid Effective gid Bit maps for signals Various flag bits Files management UMASK mask Root directory Working directory File descriptors Effective uid Effective gid System call parameters Various flag bits Some of the fields of the MINIX process table Process Control Block(PCB)

File table fd segment table page table memory task_struct eip sp eflag s eax … cs … CPU specific state of this task Swap or a.out disk memory context system context hardware context

Computer Engineering Research Laboratory 14/3 9 Process Descriptor  What each process is doing!!  This Section (Processor Descriptor) is subdivided into  Process State  Identifying a Process  Relationships Among Processes  How process are organized  Process Resource Limits Process Descriptor Process Switching Creating Processes Destroying Processes

Computer Engineering Research Laboratory 15/3 9 Process Descriptor  Overview of the Linux Process Descriptor ( struct task_struct )  This seminar (chapter 3) focus on  Process State TASK_RUNNING TASK_INTERRUPTIBLE TASK_UNINTERRUPTIBLE TASK_STOPPED TASK_TRACED TASK_ZOMBIE EXIT_DEAD  Process parent/child Relationship Process Descriptor Process Switching Creating Processes Destroying Processes

Computer Engineering Research Laboratory Task List  Representation of a process: A process descriptor of the type struct task_struct // 1.7KBytes on a 32-bit machine  Task list: A circular doubly linked list of task_struct 16

17 Threads 17 So far a process is a single thread of execution. The single thread of control allows the process to perform only one task. The user cannot simultaneously type in characters and run the spell checker with the same process. Therefore modern OSs have extended the process concept to allow a process to have multiple threads of execution.

Computer Engineering Research Laboratory 18 Program counter Thread Process Computer (a) (b) (a)Three processes each with one thread. (b)One process with three threads. Process and Threads

Computer Engineering Research Laboratory 19 Thread Usage[Tanenbaum] A word processor with three threads

Computer Engineering Research Laboratory Linux Implementation of Threads  In the Linux, each thread has a unique task_struct. Linux implements all threads as standard processes.  A thread in Linux is just a process that shares certain resources( such as an address space). 20

21 A Thread Stack Heap BSS Data Text SP PC. open files. Registers Resources

22 Sharing of threads open files. SP PC. Registers Resources Stack1 Heap BSS Data Stack2 Text SP PC. Registers Thread1 Thread2

23 CPU Switch From Process to Process P 0P 0 Save state into PCB0 reload from PCB1 Save to PCB1 Reload from PCB0 OSP 1P 1 idle

Computer Engineering Research Laboratory 24 Operations on Processes: Process Creation  Parent process create children processes, which, in turn create other processes, forming a tree of processes  Possibilities of Resource sharing  Parent and children share all resources  Children share subset of parent’s resources  Parent and child share no resources  Possibilities of Execution  Parent and children execute concurrently  Parent waits until children terminate

Computer Engineering Research Laboratory 25 Process Creation (Cont.)  Possibilities of Address space  Child duplicate of parent  Child has a program loaded into it  UNIX examples  fork system call creates a new process  exec system call used after a fork to replace the process’ memory space with a new program

Computer Engineering Research Laboratory fork() 26 Initial Process fork() Returns a new pid(child process) Returns zero Original Process Continues New Process:Child

27 fork() Stack Heap BSS Data Text. fork( ). SP PC. open files. Registers Resources pid=1000 ID Stack Heap BSS Data Text. fork( ). SP PC. open files. Registers Resources pid=1001 ID Stack Heap BSS Data Text. fork( ). SP PC. open files. Registers Resources pid=1000 ID Parent Child

Computer Engineering Research Laboratory fork() 28

Computer Engineering Research Laboratory forkOut 29

Computer Engineering Research Laboratory fork() 30 pid=999; fork() pid=1000; parent child pid=1234;pid=1452;pid=1345; running ready

Computer Engineering Research Laboratory fork() int main(){ int i; for(i=0; i<10; i++){ printf(“Process_id=%d, i=%d\n”, getpid(), i); if(i==5){ printf(“Process_id=%d: fork() to start\n”,getpid()); int forkValue=fork(); printf(“forkValue=%d\n”, forkValue); } 31

Computer Engineering Research Laboratory fork() 32

Computer Engineering Research Laboratory fork( ) output 33

Computer Engineering Research Laboratory fork()

Computer Engineering Research Laboratory fork() output

Computer Engineering Research Laboratory Process creation

Computer Engineering Research Laboratory

Thread creation

Computer Engineering Research Laboratory Thread creation

Creation of a process 40 fork() system call : It creates a new process by duplicating an existing one. The process that calls fork() is the parent, and the new process is the child. pid = fork(); in the parent process, pid is the child process ID and in the child process, pid=0; execve() system call : It creates a new address space and load a new program into it. int execve(const char *filename, char *const argv[], char *const envp[]); argv: command line argument; envp: path name, etc;

wait exit() exec() fork() parent resumes child fork() - exec()-wait()

Computer Engineering Research Laboratory forkWait

Computer Engineering Research Laboratory fork()-wait() output

Computer Engineering Research Laboratory forkWaitExeclp

Computer Engineering Research Laboratory output

Computer Engineering Research Laboratory 46 Process Termination  Process executes last statement and asks the operating system to delete it (exit)  Output data from child to parent (via wait)  Process’ resources are deallocated by operating system  Parent may terminate execution of children processes (abort)  Child has exceeded allocated resources  Task assigned to child is no longer required  If parent is exiting  Some operating system do not allow child to continue if its parent terminates  All children terminated - cascading termination

Computer Engineering Research Laboratory 47

Computer Engineering Research Laboratory Duplicating a process image #include pid_t fork(void); 48

Computer Engineering Research Laboratory Replacing a process image #include char **environ; int execl(const char *path, const char *arg0, …,(char *)0); int execlp(const char *file, const char *arg0,…,(char *)0); int execle(const char *path, const char *arg0,…,(char *)0,char *const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); int execve(const char *path, char *const argv[],char *const envp[]); 49

Computer Engineering Research Laboratory Examples of exe*() #include char *const ls_argv[]={“ls”,”-l”,0}; char *const ls_envp[]={“PATH=bin:/usr/bin”,”TERM=console”,0}; execl(“/bin/ls”,”ls”,”-l”,0); execlp(“ls”,”ls”,”-l”,0); execle(“/bin/ls”,”ls”,”-l”,0,ls_envp); execv(“/bin/ps”,ls_argv); execvp(“ls”,ls_argv); execve(“/bin/ls”, ls_argv, ls_envp); 50

Computer Engineering Research Laboratory Waiting for a process #include pid_t wait(int *stat_loc); The parent process executing wait(), pauses until its child process stops. The call returns the pid of the child process 51

Computer Engineering Research Laboratory If(pid !=0){ int stat; pid_t pid_child; pid_child = wait(&stat); printf(“Child has finished,pid_child=%d\n”,pid_child); if(stat !=0) printf(“Child finished normally\n”); else printf(“Child finished abnormally\n”); } 52

Computer Engineering Research Laboratory Zombie Processes 53 Terminated running ready new admitted waiting interrupt scheduler dispatch I/O or event waitI/O or event completion exit TTerminated Exit_Zombie Wait( )

Computer Engineering Research Laboratory 54

Computer Engineering Research Laboratory 55