
OperatingSystemsCh3 - Process Operations-fromkernel'sperspective
Operating Systems Ch3 - Process Operations -from kernel’s perspective

Processin MemoryUserspaceGlobalDynamically-variableallocatedCode+memoryconstantsLocal一variableInvoking systemProcesscalls. E.g., fork(),exec*(), wait().AccessProcessprocess'structureKernel codeinternal(PCB)with systemcallsKernelSpace2
Global variable Local variable Dynamicallyallocated memory Code + constants Process structure (PCB) Kernel code with system calls 2 Process in Memory Kernel Space User space Process Invoking system calls. E.g., fork(), exec*(), wait(). Access process’ internal

Kernel-space vs User-spaceSystemMemoryUser-spacememoryKernel-spacememory3
Kernel-space VS User-space 3 System Memory Kernel-space memory User-space memory

Kernel-space vs User-spaceSystemMemoryKernel-space memoryUser-space memoryUser-spacememoryStoringwhatAccessedby whomKernel-spacememorya
Kernel-space VS User-space 4 System Memory Kernel-space memory User-space memory Kernel-space memory User-space memory Storing what Accessed by whom

Kernel-space vs User-spaceSystemMemoryKernel-space memoryUser-spacememoryUser-spacememoryProcess'memoryKernel data structureStoringKernel codeProgram code of thewhatDevice driversprocessAccessedby whomKernel-spacememory5
Kernel-space VS User-space 5 System Memory Kernel-space memory User-space memory Kernel-space memory User-space memory Storing what Kernel data structure Kernel code Device drivers Process’ memory Program code of the process Accessed by whom

Kernel-space vs User-spaceSystemMemoryKernel-spacememoryUser-space memoryUser-spacememoryProcess'memory.Kerneldata structureStoringKernel codeProgram code of thewhatDevicedriversprocessAccessedUserprogramcode+Kernelcodeby whomkernelcodeKernel-spacememoryThekernel isinvincible!6
Kernel-space VS User-space 6 System Memory Kernel-space memory User-space memory Kernel-space memory User-space memory Storing what Kernel data structure Kernel code Device drivers Process’ memory. Program code of the process Accessed by whom Kernel code User program code + kernel code The kernel is invincible!

Process is going back and forth..Aprocesswill switchitsexecutionSystemMemoryfrom user space to kernel spaceUser-space.How?memory-throughinvokingsystemcallKernel-spacememory
Process is going back and forth. • A process will switch its execution from user space to kernel space • How? – through invoking system call 7 System Memory Kernel-space memory User-space memory

Process is going back and forth..ExampleSystemMemory- Say, the CPU is running a programcode of a processUser-spacememory-Where is the code?.User-spacememory.Recall theprocess structure in memory-Whereshouldtheprogram counterpoint to?(intel)Core"i7Kernel-spacememoryProgramcounter8
Process is going back and forth. • Example – Say, the CPU is running a program code of a process – Where is the code? • User-space memory • Recall the process structure in memory – Where should the program counter point to? 8 System Memory Kernel-space memory User-space memory Program counter

Process is going back and forth..What happens...SystemMemory- When the process is calling the system call"getpid()"User-spacememoryWhere toget the PID- PCB (in kernel-space memory)The CPU switches from the user-space tothe kernel-space, and reads the PiD日(intelCore"i7Kernel-spacememoryProgramcounter9
Process is going back and forth. • What happens. – When the process is calling the system call “getpid()” • Where to get the PID – PCB (in kernel-space memory) • The CPU switches from the user-space to the kernel-space, and reads the PID 9 System Memory Kernel-space memory User-space memory Program counter

Process is going back and forth..: After finished executing getpid()System Memory-Whathappens?User-space-CPU switches back to theuser-spacememorymemory, and continues running thatprogram code日CintelCore"i7Kernel-spacememoryProgramcounter10
Process is going back and forth. • After finished executing getpid() – What happens? – CPU switches back to the user-space memory, and continues running that program code 10 System Memory Kernel-space memory User-space memory Program counter