Chapter 3 Processes What is a process A

















- Slides: 17
Chapter 3 – Processes What is a process? A Program in execution A running program Maybe threads Always memory File descriptors
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; Zero. Memory( &si, sizeof(si) ); si. cb = sizeof(si); Zero. Memory( &pi, sizeof(pi) ); if (! Create. Process ( TEXT("F: \C++ Programs\Hangman\Debug\Hangman. exe"), NULL, FALSE, CREATE_NEW_CONSOLE, 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+v 2. 6. 35/include/linux/sched. h #L 1173
How to make a process PID 1 is special Otherwise. . .
Fork/Exec
Process Tree
Process Tree
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.
Memory Map for a Process
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.