



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth explanation of processes in operating systems, including process creation, termination, states, and process control block. It also covers process scheduling and context switching.
Typology: Study notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




CS423UG Operating Systems
CS 423UG - Operating Systems, Indranil Gupta 2
Processes: pronounced as “process-ees”, rhymes with “armies”; to avoid confusion with “processors”.
CS 423UG - Operating Systems, Indranil Gupta 3
CS 423UG - Operating Systems, Indranil Gupta 4
CS 423UG - Operating Systems, Indranil Gupta 5
CS 423UG - Operating Systems, Indranil Gupta 6
Listing all running processes Windows: Task Manager Unix/Linux> “ps –all” PID TTY TIME CMD 1625 pts/6 0:02 tcsh 17246 pts/1 0:35 pine 1272 pts/7 0:00 ps 8865 pts/3 0:01 emacs
Examples of running processes: Command Shell (e.g., tcsh) Editors: pine (also emacs, vim, etc.) Others: Firefox windows (each firefox window is a separate process) And “ps” itself appears as a process!
CS 423UG - Operating Systems, Indranil Gupta 7
Concretely! Can we define the
term “process”?
CS 423UG - Operating Systems, Indranil Gupta 8
A Process, Pictorially
PC (hex): 00d
CS 423UG - Operating Systems, Indranil Gupta 9
Hmm… how does one “play”
around with a process?
A user process may be given kernel privilege sometimes (e.g., once it executes a TRAP)
CS 423UG - Operating Systems, Indranil Gupta 10
“New Rules” for Process
Management (with apologies to
Bill Maher):
CS 423UG - Operating Systems, Indranil Gupta 11
Process Creation
CS 423UG - Operating Systems, Indranil Gupta 12
Forks
int parentpid; int childpid;
if ((childpid = fork()) == -1) { perror(can’t create a new process); exit(1); } else if (childpid == 0) {/* child process executes / printf(“child: childpid = %d, parentpid = %d \n”, getpid(), getppid()); exit(0); } else { /parent process executes */ printf(“parent: childpid = %d, parentpid = %d \n”, childpid, getpid()); exit(0); }
Suppose the OS is running this, and it executes the fork() instruction
CS 423UG - Operating Systems, Indranil Gupta 19
Process: A Manipulatable
Object
CS 423UG - Operating Systems, Indranil Gupta 20
Process State
“state” as in “state of the union”, not as in “state of Idaho”
CS 423UG - Operating Systems, Indranil Gupta 21
The Process Model
(as seen by OS)
(as seen by CPU)
(as seen in memory)
CS 423UG - Operating Systems, Indranil Gupta 22
Well, so I lied. A process’
condition also consists of ...
Process State new, ready, running, waiting, halted; Program Counter the address of the next instruction to be executed for this process; CPU Registers index registers, stack pointers, general purpose registers; CPU Scheduling Information process priority and pointer; Memory Management Information base/limit information; Accounting Information time limits, process number; owner I/O Status Information list of I/O devices allocated to the process;
All present in OS-maintained data structure called PCB=process control block, for each process that has not been terminated
CS 423UG - Operating Systems, Indranil Gupta 23
Process Control Block (PCB)
e.g.: Linux: struct task_struct (^) CS 423UG - Operating Systems, Indranil Gupta 24
Remember This?
CS 423UG - Operating Systems, Indranil Gupta 25
Main Memory/
Main Memory
(code,data, stack) PID 902 (code,data, stack)
Set aside for OS/kernel use only
CS 423UG - Operating Systems, Indranil Gupta 26
Process Address Space
Why is this needed? Remember system call libraries?
(code,data, stack)
CS 423UG - Operating Systems, Indranil Gupta 27
Process Scheduling
CS 423UG - Operating Systems, Indranil Gupta 28
Context Switch
Your switching back and forth betw. HW’s for different courses
CS 423UG - Operating Systems, Indranil Gupta 29
Process Context Switch
Save PCB-
Reload from PCB-
Save into PCB-
Reload from PCB-
exec
exec
idle
idle
exec
idle
Interrupt/system call
Interrupt/ System call
OS jobs
CS 423UG - Operating Systems, Indranil Gupta 30
“Process”? Hey, Ah That’s it!