Download presentation
Presentation is loading. Please wait.
Published byPeregrine Warner Modified over 9 years ago
1
LINUX System : Lecture 7 Process Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System
2
2 Process Management
3
What is Process? Definition –an instance of a running program (runnable program) –an execution environment of a program –scheduling entity –a control flow and address space –PCB (Process Control Block) : proc. table and U area Manipulation of Process –create, destroy –context –state transition dispatch (context switch) sleep, wakeup swap
4
Process State Transition user running kernel running zombie initial (idle) fork ready to run suspended ready asleep suspended asleep return from syscall or interrupt syscall, interrupt swtchsleep, lock wakeup, unlock exit wait swap swtch (Source : UNIX Internals)
5
Context proc table U area segment tablepage table memory disk fd file table Registers (TSS) eip sp eflags eax cs context : system context, address (memory) context, H/W context …. swap
6
Context : system context System context –proc. Table identification: pid, process group id, … family relation state sleep channel: sleep queue scheduling information : p_cpu, p_pri, p_nice,.. signal handling information address (memory) information –U area (swappable information) stores hardware context when the process is not running currently UID, GID arguments, return values, and error status for system call signal catch function file descriptor usage statistics
7
Context : address context fork example guess what can we get from this program? intglob = 6; charbuf[] = “a write to stdout\n”; int main(void) { int var; pid_t pid; var = 88; write(STDOUT_FILENO, buf, sizeof(buf)-1); printf(“before fork\n”); if ((pid = fork()) == 0) {/* child */ glob++; var++; } else sleep(2);/* parent */ printf(“pid = %d, glob = %d, var = %d\n”, getpid(), glob, var); exit (0); } (Source : Adv. programming in the UNIX Env., pgm 8.1)
8
Context : address context fork internal : compile results test.c gcc header text data bss stack user’s perspective (virtual address) … movl %eax, [glob] addl %eax, 1 movl [glob], %eax... glob, buf var, pid text data stack kernel 0xffffffff 0xbfffffff 0x0 a.out Executable and Linking Format
9
Context : address context fork internal : before fork (after run a.out) cf) we assume that there is no paging mechanism in this figure. memory text stack data segment T. proc T. pid = 11 glob, buf var, pid
10
Context : address context fork internal : after fork – address space : basic protection barrier memory text stack data segment T. proc T. pid = 11 segment T. proc T. pid = 12 stack data glob, buf var, pid glob, buf
11
Context : address context fork internal : with COW (Copy on Write) mechanism after fork with COW after “glob++” operation memory text stack data segment T. proc T. pid = 11 segment T. proc T. pid = 12 text stack data segment T. proc T. pid = 11 segment T. proc T. pid = 12 data
12
12 Context : address context execve internal header text data bss stack a.out memory text stack data segment T. proc T. pid = 11 stack data text
13
13 Context : hardware context time sharing (multitasking) process 1 process 2 process 3 time quantum … Where am I ??
14
14 Context : hardware context brief reminds the 80x86 architecture ALU Control Unit Registers INOUT eip, eflags eax, ebx, ecx, edx, esi, edi, … cs, ds, ss, es,... cr0, cr1, cr2, cr3, GDTR, TR,...
15
15 Context : hardware context context swtch U area Proc T.TSS eip sp eflags eax cs CPU U area Proc T.TSS eip sp eflags eax cs restore context save context
16
16 Context : hardware context context swtch : pseudo-code in UNIX … /* need context swtch */ if (save_context()) { /* pick another process to run from ready queue */ …. restore_context(new process) /* The control does not arrive here, NEVER !!! */ } /* resuming process executes from here !!! */ …... (Source : The Design of the UNIX OS)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.