1 / 16

LINUX System : Lecture 7 Process

LINUX System : Lecture 7 Process. Bong-Soo Sohn. Lecture notes acknowledgement : The design of UNIX Operating System. Process Management. What is Process?. Definition an instance of a running program (runnable program) an execution environment of a program scheduling entity

levia
Télécharger la présentation

LINUX System : Lecture 7 Process

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LINUX System : Lecture 7Process Bong-Soo Sohn Lecture notes acknowledgement : The design of UNIX Operating System

  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 return from syscall or interrupt syscall, interrupt fork initial (idle) wait exit zombie kernel running swtch sleep, lock swtch ready to run asleep wakeup, unlock swap swap suspended ready suspended asleep (Source : UNIX Internals)

  5. Context • context : system context, address (memory) context, H/W context memory proc table segment table page table file table fd Registers (TSS) swap eip sp eflags eax U area …. disk cs ….

  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? int glob = 6; char buf[] = “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 gcc … movl %eax, [glob] addl %eax, 1 movl [glob], %eax ... test.c header text glob, buf 0xffffffff data kernel 0xbfffffff bss var, pid stack stack a.out data Executable and Linking Format text 0x0 user’s perspective (virtual address)

  9. Context : address context memory • fork internal : before fork (after run a.out) cf) we assume that there is no paging mechanism in this figure. proc T. segment T. text pid = 11 var, pid stack glob, buf data

  10. Context : address context memory glob, buf • fork internal : after fork • address space : basic protection barrier proc T. segment T. data pid = 11 text var, pid stack proc T. segment T. glob, buf pid = 12 data var, pid stack

  11. Context : address context • fork internal : with COW (Copy on Write) mechanism after fork with COWafter “glob++” operation memory segment T. segment T. proc T. proc T. data pid = 11 text pid = 11 text stack stack segment T. segment T. proc T. proc T. pid = 12 pid = 12 data data

  12. a.out header text data bss stack Context : address context • execve internal memory proc T. segment T. data pid = 11 text stack text data stack

  13. Context : hardware context • time sharing (multitasking) Where am I ?? time quantum process 1 … process 2 process 3

  14. Context : hardware context • brief reminds the 80x86 architecture ALU Control Unit IN OUT Registers eip, eflags eax, ebx, ecx, edx, esi, edi, … cs, ds, ss, es, ... cr0, cr1, cr2, cr3, GDTR, TR, ...

  15. TSS TSS eip eip sp sp eflags eflags eax eax cs cs Context : hardware context • context swtch CPU restore context save context Proc T. Proc T. U area U area

  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)

More Related