Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.

Similar presentations


Presentation on theme: "ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH."— Presentation transcript:

1 ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi mjchoi@postech.ac.kr DPNM Lab. Dept. of CSE, POSTECH

2 ITEC502 컴퓨터 시스템 및 실습 2 Contents 1.Processes –Process Concept –The Process Model –Process Creation –Process Termination –Process Hierarchies –Process States –Implementation of Processes

3 ITEC502 컴퓨터 시스템 및 실습 3 Process Concept  An operating system executes a variety of programs: –Batch system – jobs –Time-shared systems – user programs or tasks  Uses the terms job and process almost interchangeably  Process – a program in execution; process execution must progress in sequential fashion  A process includes: –program counter –stack –data section

4 ITEC502 컴퓨터 시스템 및 실습 4 Process in Memory  Current activity of a process is represented by –the value of program counter –The contents of the processor ’ s registers  Stack –contains temporary data –function parameters, return address, local variables  Data section –contains global variables  Heap –is a memory that is dynamically allocated during process run time  Program is a passive entity  Process is a active entity  Two processes may be associated with the same program

5 ITEC502 컴퓨터 시스템 및 실습 5 Processes: The Process Model  Multiprogramming of four programs  Conceptual model of 4 independent, sequential processes  Only one program active at any instant

6 ITEC502 컴퓨터 시스템 및 실습 6 Process Creation (1) Principal events that cause process creation 1.System initialization 2.Execution of a process creation system 3.User request to create a new process 4.Initiation of a batch job

7 ITEC502 컴퓨터 시스템 및 실습 7 Process Creation (2)  Parent process create children processes, which, in turn create other processes, forming a tree of processes – via create-process system call  Three possibilities in terms of resource sharing –Parent and children share all resources –Children share subset of parent ’ s resources –Parent and child share no resources, child receives resources from OS directly  Two possibilities in terms of execution –Parent and children execute concurrently –Parent waits until children terminate

8 ITEC502 컴퓨터 시스템 및 실습 8 Process Creation (3)  Two possibilities in terms of address space –Child is a duplicate of parent; child has same program and data as the parent –Child has a program loaded into it  UNIX examples –fork system call creates new process –exec system call used after a fork to replace the process ’ memory space with a new program

9 ITEC502 컴퓨터 시스템 및 실습 9 fork() & exec()  A new process is created by the fork() system call  The new process consists of a copy of the address space of the original process  Both processes (parent & child) continue execution at the instruction after the fork().  The return code for the fork() is zero for the child process, whereas the (nonzero) pid of the child process is returned to the parent  The exec() loads a binary file into memory, destroys the memory image of the program, and starts its execution

10 ITEC502 컴퓨터 시스템 및 실습 10 C Program Forking – UNIX (1) int main() { pid_t pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execve("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); }

11 ITEC502 컴퓨터 시스템 및 실습 11 C Program Forking – UNIX (2)

12 ITEC502 컴퓨터 시스템 및 실습 12 Process Creation – Win32  Windows example –CreateProcess() function is used, which is similar to fork –creates a new child process –requires loading a specified program into the address space of the child process at process creation –expects no fewer than ten parameters

13 ITEC502 컴퓨터 시스템 및 실습 13 C Program Forking – Wind32 (1) void _tmain( int argc, TCHAR *argv[] ) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); // Start the child process if( !CreateProcess( NULL, // No module name (use command line) “c:\\Windows\\system32\mspaint.exe”, // program name NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Pointer to PROCESS_INFORMATION structure )

14 ITEC502 컴퓨터 시스템 및 실습 14 C Program Forking – Win32 (2) { printf( "CreateProcess failed (%d)\n", GetLastError() ); return; } // Wait until child process exits WaitForSingleObject( pi.hProcess, INFINITE ); // Close process and thread handles CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); }

15 ITEC502 컴퓨터 시스템 및 실습 15 Process Termination (1) Conditions which terminate processes 1.Normal exit (voluntary) 2.Error exit (voluntary) 3.Fatal error (involuntary) 4.Killed by another process (involuntary)

16 ITEC502 컴퓨터 시스템 및 실습 16 Process Termination (2)  Process executes last statement and asks the operating system to delete it (exit) –Status value returned from child to parent (via wait) –Process ’ resources are deallocated by operating system Memory, open files, I/O buffers  Parent may terminate execution of children processes (abort) with various reason –Child has exceeded allocated resources –Task assigned to child is no longer required  If parent is exiting Some operating systems do not allow child to continue if its parent terminates –All children terminated - cascading termination

17 ITEC502 컴퓨터 시스템 및 실습 17 Process Hierarchies  Parent creates a child process, child processes can create its own process  Forms a hierarchy –UNIX calls this a "process group"  Windows has no concept of process hierarchy –all processes are created equal

18 ITEC502 컴퓨터 시스템 및 실습 18 Process States (1): 3 states  Possible process states –running –blocked –ready  Transitions between states shown

19 ITEC502 컴퓨터 시스템 및 실습 19 Process States (2)  Lowest layer of process-structured OS –handles interrupts, scheduling  Above that layer are sequential processes

20 ITEC502 컴퓨터 시스템 및 실습 20 Process States – 5 states  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 processor (CPU) –terminated: The process has finished execution  The state of a process is defined in part by the current activity of that process

21 ITEC502 컴퓨터 시스템 및 실습 21 Diagram of Process States  It is important to realize that only one process can be running on any processor at any instant  Many processes may be ready and waiting states

22 ITEC502 컴퓨터 시스템 및 실습 22 Process Control Block (PCB) (1)  Each process is represented in the operating system by a 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

23 ITEC502 컴퓨터 시스템 및 실습 23 Process Control Block (PCB) (2)  Process state –New, ready, running, waiting, terminated  Program counter –The address of the next instruction to be executed for this process  CPU registers –Accumulators, index registers, stack pointers, and general-purpose registers, etc.  CPU scheduling information –Process priority, pointers to scheduling queue, etc.  Memory-management information –Value of base and limit registers, the page tables or segment tables, etc.  Accounting information –The amount of CPU and real time used, time limits, account number, job and process number  I/O status information –List of I/O devices allocated, open files, etc.

24 ITEC502 컴퓨터 시스템 및 실습 24 CPU Switch From Process to Process

25 ITEC502 컴퓨터 시스템 및 실습 25 Implementation of Processes (1) Fields of a process table entry

26 ITEC502 컴퓨터 시스템 및 실습 26 Implementation of Processes (2) Skeleton of what lowest level of OS does when an interrupt occurs

27 ITEC502 컴퓨터 시스템 및 실습 27 Summary  A process is a program in execution  As a process executes, the process may be in one of the 3 states or 5 states: –running, blocked, ready –new, ready, running, waiting, terminated  Each process is represented in the OS by its PCB  OS provides a mechanism for parent process to create a child process

28 ITEC502 컴퓨터 시스템 및 실습 28 Review 1.Processes –Process Concept –The Process Model –Process Creation –Process Termination –Process Hierarchies –Process States –Implementation of Processes


Download ppt "ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH."

Similar presentations


Ads by Google