SlideShare a Scribd company logo
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 1
Processes in
Unix, Linux, and Windows
CS-3013, Operating Systems
A-term 2009
(Slides include materials from Modern Operating Systems, 3rd ed., by Andrew Tanenbaum and from
Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne)
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 2
Processes in Unix, Linux, and Windows
• In previous topic, we used “process” in a
generic way to represent the abstraction of
concurrency
• Unix pre-empted generic term “process” to
mean something very specific
• Linux and Windows adopted Unix definition
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 3
Process in Unix-Linux-Windows
comprises
• an address space – usually protected and virtual – mapped
into memory
• the code for the running program
• the data for the running program
• an execution stack and stack pointer (SP); also heap
• the program counter (PC)
• a set of processor registers – general purpose and status
• a set of system resources
– files, network connections, pipes, …
– privileges, (human) user association, …
• …
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 4
Reading Assignment
• Tanenbaum, §2.1
– Also §10.3.1, 10.3.2
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 5
Process Address Space (traditional Unix)
0x00000000
0xFFFFFFFF
(Virtual)
address space
program code
(text)
static data
heap
(dynamically allocated)
stack
(dynamically allocated)
PC
SP
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 6
Processes in the OS – Representation
• To users (and other processes) a process is
identified by its Process ID (PID)
• In the OS, processes are represented by entries in a
Process Table (PT)
– PID is index to (or pointer to) a PT entry
– PT entry = Process Control Block (PCB)
• PCB is a large data structure that contains or
points to all info about the process
– Linux – defined in task_struct (over 70 fields)
• see include/linux/sched.h
– Windows XP – defined in EPROCESS – about 60 fields
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 7
Processes in the OS – PCB
• Typical PCB contains:
– execution state
– PC, SP & processor registers – stored when
process is not in running state
– memory management info
– privileges and owner info
– scheduling priority
– resource info
– accounting info
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 8
Process – starting and ending
• Processes are created …
– When the system boots
– By the actions of another process (more later)
– By the actions of a user
– By the actions of a batch manager
• Processes terminate …
– Normally – exit
– Voluntarily on an error
– Involuntarily on an error
– Terminated (killed) by action of
• a user or
• another process
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 9
Processes – States
• Process has an execution state
– ready: waiting to be assigned to CPU
– running: executing on the CPU
– waiting: waiting for an event, e.g. I/O
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 10
Processes – State Queues
• The OS maintains a collection of process state
queues
– typically one queue for each state – e.g., ready, waiting,
…
– each PCB is put onto a queue according to its current
state
– as a process changes state, its PCB is unlinked from one
queue, and linked to another
• Process state and the queues change in response to
events – interrupts, traps
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 11
Processes – Privileges
• Users are given privileges by the system
administrator
• Privileges determine what rights a user has
for an object.
– Unix/Linux – Read|Write|eXecute by user,
group and “other” (i.e., “world”)
– WinNT – Access Control List
• Processes “inherit” privileges from user
– or from creating process
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 12
Process Creation – Unix & Linux
• Create a new (child) process – fork();
– Allocates new PCB
– Clones the calling process (almost exactly)
• Copy of parent process address space
• Copies resources in kernel (e.g. files)
– Places new PCB on Ready queue
– Return from fork() call
• 0 for child
• child PID for parent
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 13
Example of fork( )
int main(int argc, char **argv)
{
char *name = argv[0];
int child_pid = fork();
if (child_pid == 0) {
printf("Child of %s sees PID of %dn",
name, child_pid);
return 0;
} else {
printf("I am the parent %s. My child is %dn",
name, child_pid);
return 0;
}
}
_______________________________
% ./forktest
Child of forktest sees PID of 0
I am the parent forktest. My child is 486
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 14
Starting New Programs
• Unix & Linux:–
– int exec (char *prog, char **argv)
– Check privileges and file type
– Loads program at path prog into address space
• Replacing previous contents!
• Execution starts at main()
– Initializes context – e.g. passes arguments
•*argv
– Place PCB on ready queue
– Preserves, pipes, open files, privileges, etc.
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 15
Executing a New Program
(Linux-Unix)
• fork() followed by exec()
• Creates a new process as clone of previous
one
• I.e., same program, but different execution of it
• First thing that clone does is to replace itself
with new program
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 16
Fork + Exec – shell-like
int main(int argc, char **argv)
{ char *argvNew[5];
int pid;
if ((pid = fork()) < 0) {
printf( "Fork errorn“);
exit(1);
} else if (pid == 0) { /* child process */
argvNew[0] = "/bin/ls"; /* i.e., the new program */
argvNew[1] = "-l";
argvNew[2] = NULL;
if (execve(argvNew[0], argvNew, environ) < 0) {
printf( "Execve errorn“);
exit(1); /* program should not reach this point */
}
} else { /* parent */
wait(pid); /* wait for the child to finish */
}
}
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 17
Waiting for a Process
• Multiple variations of wait function
• Including non-blocking wait functions
• Waits until child process terminates
• Acquires termination code from child
• Child process is destroyed by kernel
• Zombie:– a process that had never been waited for
• Hence, cannot go away!
• See Love, Linux Kernel Development, pp 37-38
• See Tanenbaum, §10.3.2
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 18
Processes – Windows
• Windows NT/XP – combines fork & exec
– CreateProcess(10 arguments)
– Not a parent child relationship
– Note – privileges required to create a new
process
– See Tanenbaum, §11.4
– (More in this section than we have discussed so far)
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 19
Traditional Unix
• Processes are in separate address spaces
• By default, no shared memory
• Processes are unit of scheduling
• A process is ready, waiting, or running
• Processes are unit of resource allocation
• Files, I/O, memory, privileges, …
• Processes are used for (almost) everything!
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 20
Windows and Linux
• Threads (next topic) are units of scheduling
• Threads are used for everything
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 25
Reading Assignment
• Tanenbaum, §2.1 & §10.3.1–10.3.2
Processes in Unix,
Linux, and Windows
CS-3013 A-term 2009 26
Questions?
Project 1 Assignment

More Related Content

Similar to Processes in Linux.ppt

11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt
SIDDHARTHANANDCSE202
 
Process management
Process managementProcess management
Process management
Akshay Ithape
 
UNIX Basics and Cluster Computing
UNIX Basics and Cluster ComputingUNIX Basics and Cluster Computing
UNIX Basics and Cluster Computing
Bioinformatics and Computational Biosciences Branch
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
pavimalpani
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
Emertxe Information Technologies Pvt Ltd
 
LSA2 - 02 Namespaces
LSA2 - 02  NamespacesLSA2 - 02  Namespaces
LSA2 - 02 Namespaces
Marian Marinov
 
Input and Output Devices and Systems
Input and Output Devices and SystemsInput and Output Devices and Systems
Input and Output Devices and SystemsNajma Alam
 
operating system
operating systemoperating system
operating system
Ibbad shah
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
GRajendra
 
Ali.ppt
Ali.pptAli.ppt
Chapter-01.ppt
Chapter-01.pptChapter-01.ppt
Chapter-01.ppt
HanifeMehan
 
3 process management
3 process management3 process management
3 process management
Dr. Loganathan R
 
OPERATING SYSTEM
OPERATING SYSTEMOPERATING SYSTEM
OPERATING SYSTEM
sathish sak
 
Ch3 processes
Ch3   processesCh3   processes
Ch3 processes
Welly Dian Astika
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
Kathirvel Ayyaswamy
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questionsTeja Bheemanapally
 
SDE TP 4 - Processus
SDE TP 4 - ProcessusSDE TP 4 - Processus
SDE TP 4 - Processus
Alexandru Radovici
 

Similar to Processes in Linux.ppt (20)

Unix kernal
Unix kernalUnix kernal
Unix kernal
 
11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt
 
Process management
Process managementProcess management
Process management
 
UNIX Basics and Cluster Computing
UNIX Basics and Cluster ComputingUNIX Basics and Cluster Computing
UNIX Basics and Cluster Computing
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
LSA2 - 02 Namespaces
LSA2 - 02  NamespacesLSA2 - 02  Namespaces
LSA2 - 02 Namespaces
 
Input and Output Devices and Systems
Input and Output Devices and SystemsInput and Output Devices and Systems
Input and Output Devices and Systems
 
operating system
operating systemoperating system
operating system
 
Chapter 01
Chapter 01Chapter 01
Chapter 01
 
Lecture 5 process concept
Lecture 5   process conceptLecture 5   process concept
Lecture 5 process concept
 
Ali.ppt
Ali.pptAli.ppt
Ali.ppt
 
Chapter-01.ppt
Chapter-01.pptChapter-01.ppt
Chapter-01.ppt
 
3 process management
3 process management3 process management
3 process management
 
OPERATING SYSTEM
OPERATING SYSTEMOPERATING SYSTEM
OPERATING SYSTEM
 
Ch3 processes
Ch3   processesCh3   processes
Ch3 processes
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Linux or unix interview questions
Linux or unix interview questionsLinux or unix interview questions
Linux or unix interview questions
 
SDE TP 4 - Processus
SDE TP 4 - ProcessusSDE TP 4 - Processus
SDE TP 4 - Processus
 
02unixintro
02unixintro02unixintro
02unixintro
 

More from jguuhxxxfp

Operating Systems.pptx
Operating Systems.pptxOperating Systems.pptx
Operating Systems.pptx
jguuhxxxfp
 
Input Output Overview.ppt
Input Output Overview.pptInput Output Overview.ppt
Input Output Overview.ppt
jguuhxxxfp
 
Project Report.pptx
Project Report.pptxProject Report.pptx
Project Report.pptx
jguuhxxxfp
 
College Placement Project.pptx
College Placement Project.pptxCollege Placement Project.pptx
College Placement Project.pptx
jguuhxxxfp
 
Computer System.ppt
Computer System.pptComputer System.ppt
Computer System.ppt
jguuhxxxfp
 
Disks and Stable Storage.ppt
Disks and Stable Storage.pptDisks and Stable Storage.ppt
Disks and Stable Storage.ppt
jguuhxxxfp
 
emp-internet07.ppt
emp-internet07.pptemp-internet07.ppt
emp-internet07.ppt
jguuhxxxfp
 

More from jguuhxxxfp (7)

Operating Systems.pptx
Operating Systems.pptxOperating Systems.pptx
Operating Systems.pptx
 
Input Output Overview.ppt
Input Output Overview.pptInput Output Overview.ppt
Input Output Overview.ppt
 
Project Report.pptx
Project Report.pptxProject Report.pptx
Project Report.pptx
 
College Placement Project.pptx
College Placement Project.pptxCollege Placement Project.pptx
College Placement Project.pptx
 
Computer System.ppt
Computer System.pptComputer System.ppt
Computer System.ppt
 
Disks and Stable Storage.ppt
Disks and Stable Storage.pptDisks and Stable Storage.ppt
Disks and Stable Storage.ppt
 
emp-internet07.ppt
emp-internet07.pptemp-internet07.ppt
emp-internet07.ppt
 

Recently uploaded

space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 

Recently uploaded (20)

space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 

Processes in Linux.ppt

  • 1. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 1 Processes in Unix, Linux, and Windows CS-3013, Operating Systems A-term 2009 (Slides include materials from Modern Operating Systems, 3rd ed., by Andrew Tanenbaum and from Operating System Concepts, 7th ed., by Silbershatz, Galvin, & Gagne)
  • 2. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 2 Processes in Unix, Linux, and Windows • In previous topic, we used “process” in a generic way to represent the abstraction of concurrency • Unix pre-empted generic term “process” to mean something very specific • Linux and Windows adopted Unix definition
  • 3. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 3 Process in Unix-Linux-Windows comprises • an address space – usually protected and virtual – mapped into memory • the code for the running program • the data for the running program • an execution stack and stack pointer (SP); also heap • the program counter (PC) • a set of processor registers – general purpose and status • a set of system resources – files, network connections, pipes, … – privileges, (human) user association, … • …
  • 4. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 4 Reading Assignment • Tanenbaum, §2.1 – Also §10.3.1, 10.3.2
  • 5. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 5 Process Address Space (traditional Unix) 0x00000000 0xFFFFFFFF (Virtual) address space program code (text) static data heap (dynamically allocated) stack (dynamically allocated) PC SP
  • 6. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 6 Processes in the OS – Representation • To users (and other processes) a process is identified by its Process ID (PID) • In the OS, processes are represented by entries in a Process Table (PT) – PID is index to (or pointer to) a PT entry – PT entry = Process Control Block (PCB) • PCB is a large data structure that contains or points to all info about the process – Linux – defined in task_struct (over 70 fields) • see include/linux/sched.h – Windows XP – defined in EPROCESS – about 60 fields
  • 7. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 7 Processes in the OS – PCB • Typical PCB contains: – execution state – PC, SP & processor registers – stored when process is not in running state – memory management info – privileges and owner info – scheduling priority – resource info – accounting info
  • 8. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 8 Process – starting and ending • Processes are created … – When the system boots – By the actions of another process (more later) – By the actions of a user – By the actions of a batch manager • Processes terminate … – Normally – exit – Voluntarily on an error – Involuntarily on an error – Terminated (killed) by action of • a user or • another process
  • 9. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 9 Processes – States • Process has an execution state – ready: waiting to be assigned to CPU – running: executing on the CPU – waiting: waiting for an event, e.g. I/O
  • 10. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 10 Processes – State Queues • The OS maintains a collection of process state queues – typically one queue for each state – e.g., ready, waiting, … – each PCB is put onto a queue according to its current state – as a process changes state, its PCB is unlinked from one queue, and linked to another • Process state and the queues change in response to events – interrupts, traps
  • 11. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 11 Processes – Privileges • Users are given privileges by the system administrator • Privileges determine what rights a user has for an object. – Unix/Linux – Read|Write|eXecute by user, group and “other” (i.e., “world”) – WinNT – Access Control List • Processes “inherit” privileges from user – or from creating process
  • 12. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 12 Process Creation – Unix & Linux • Create a new (child) process – fork(); – Allocates new PCB – Clones the calling process (almost exactly) • Copy of parent process address space • Copies resources in kernel (e.g. files) – Places new PCB on Ready queue – Return from fork() call • 0 for child • child PID for parent
  • 13. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 13 Example of fork( ) int main(int argc, char **argv) { char *name = argv[0]; int child_pid = fork(); if (child_pid == 0) { printf("Child of %s sees PID of %dn", name, child_pid); return 0; } else { printf("I am the parent %s. My child is %dn", name, child_pid); return 0; } } _______________________________ % ./forktest Child of forktest sees PID of 0 I am the parent forktest. My child is 486
  • 14. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 14 Starting New Programs • Unix & Linux:– – int exec (char *prog, char **argv) – Check privileges and file type – Loads program at path prog into address space • Replacing previous contents! • Execution starts at main() – Initializes context – e.g. passes arguments •*argv – Place PCB on ready queue – Preserves, pipes, open files, privileges, etc.
  • 15. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 15 Executing a New Program (Linux-Unix) • fork() followed by exec() • Creates a new process as clone of previous one • I.e., same program, but different execution of it • First thing that clone does is to replace itself with new program
  • 16. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 16 Fork + Exec – shell-like int main(int argc, char **argv) { char *argvNew[5]; int pid; if ((pid = fork()) < 0) { printf( "Fork errorn“); exit(1); } else if (pid == 0) { /* child process */ argvNew[0] = "/bin/ls"; /* i.e., the new program */ argvNew[1] = "-l"; argvNew[2] = NULL; if (execve(argvNew[0], argvNew, environ) < 0) { printf( "Execve errorn“); exit(1); /* program should not reach this point */ } } else { /* parent */ wait(pid); /* wait for the child to finish */ } }
  • 17. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 17 Waiting for a Process • Multiple variations of wait function • Including non-blocking wait functions • Waits until child process terminates • Acquires termination code from child • Child process is destroyed by kernel • Zombie:– a process that had never been waited for • Hence, cannot go away! • See Love, Linux Kernel Development, pp 37-38 • See Tanenbaum, §10.3.2
  • 18. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 18 Processes – Windows • Windows NT/XP – combines fork & exec – CreateProcess(10 arguments) – Not a parent child relationship – Note – privileges required to create a new process – See Tanenbaum, §11.4 – (More in this section than we have discussed so far)
  • 19. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 19 Traditional Unix • Processes are in separate address spaces • By default, no shared memory • Processes are unit of scheduling • A process is ready, waiting, or running • Processes are unit of resource allocation • Files, I/O, memory, privileges, … • Processes are used for (almost) everything!
  • 20. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 20 Windows and Linux • Threads (next topic) are units of scheduling • Threads are used for everything
  • 21. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 25 Reading Assignment • Tanenbaum, §2.1 & §10.3.1–10.3.2
  • 22. Processes in Unix, Linux, and Windows CS-3013 A-term 2009 26 Questions? Project 1 Assignment