170 likes | 208 Views
A comprehensive overview of what a process entails in a program's execution, including threads, memory, and file descriptors. Learn about creating, terminating, and managing processes in different operating systems.
E N D
What is a process? A Program in execution A running program Maybe threads Always memory File descriptors Chapter 3 – Processes
What does the OS Have to Do? • Create proc • Delete/Kill Proc • Start/Stop Proc • Allocate RAM • Allocate CPU time
How to make a windows process STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); if (! CreateProcess ( TEXT("F:\\C++\\C++ Programs\\Hangman\\Debug\\Hangman.exe"), NULL,NULL,NULL,FALSE, CREATE_NEW_CONSOLE, NULL,NULL, &si, &pi ) ) { cout << "Unable to execute."; }
Windows does it differently Faster but less flexible.
What does a process look like in the kernel? • It’s a data structure • What RAM • What threads • What file descriptors • Process State/PC/CPU registers/Accounting/... • Etc. • Book says “Process control block”. Linux says “task_struct”. • http://lxr.linux.no/linux+v2.6.35/include/linux/sched.h#L1173
How to make a process PID 1 is special Otherwise ...
Process Termination Call exit Make an error Have someone kill you Bruce Willis
Process Control Block A Process Control Block is a data structure in the kernel that records information about the process. (struct task_struct in Linux) Process ID State (running, waiting) Memory CPU Registers User/Permission Which file descriptors Etc.
Memory Maps • There is a thing called the MMU • It makes where ram is look different for each process. • Comes in a later chapter.
Multiple Processes for the same Program • Draw on board • What is shared? • What is not shared?
Lifetime of a Process Draw Diagram Label causes of movement.
Scheduling We multi-task (later chapter) Short Term Scheduler – the normal one Works on the millisecond basis Maximize work / Minimize latency Long Term Scheduler – if it exists Works on the minute/hour/day basis Keep the system not overloaded
Definition: Context Switch Context switch: Change from running a thread or process to another. Interrupt gives kernel control, in privileged mode Stop the thread. Save state (CPU reg, PC, etc.) Change memory map Go back to user mode Load new state. Jump to resume other thread.