200 likes | 253 Views
Lecture 10: Processes II-A. Process States Process vs. Thread Background/Foreground. Process States. We’ve mentioned these before: Running Idle/Sleeping Waiting for I/O Zombie Now a new one: Swapped Out. “Swapped Out” State. We only have so much CPU power
E N D
Lecture 10: Processes II-A • Process States • Process vs. Thread • Background/Foreground
Process States • We’ve mentioned these before: • Running • Idle/Sleeping • Waiting for I/O • Zombie • Now a new one: • Swapped Out
“Swapped Out” State • We only have so much CPU power • Can’t run everything at the same time • The processes must share • How do we decide who gets processor time? • Does this question sound familiar?
“Swapped Out” State • We only have so much CPU power • Can’t run everything at the same time • The processes must share • How do we decide who gets processor time? • Does this question sound familiar? • Similar to memory management!
Process Priority • Linux • “Niceness” level • -20 (greedy) to +20 (charitable) • Windows • IDLE_PRIORITY_CLASS • BELOW_NORMAL_PRIORITY_CLASS • NORMAL_PRIORITY_CLASS • ABOVE_NORMAL_PRIORITY_CLASS • HIGH_PRIORITY_CLASS • REALTIME_PRIORITY_CLASS
Process Priority • Setting high priorities can be bad • Why?
Process Priority • Setting high priorities can be bad • Why? • Other processes get neglected • Those other processes may be system processes • Neglected system processes can degrade performance of your process
Process Management • On modern computers, we want to run tasks “simultaneously”… • …by interweaving • Single CPU • Appears simultaneous to us • …in parallel • Multiple CPUs • Truly simultaneous! • For upcoming slides, we’re interweaving
Process • Created out of a program • Communicates with peers via interprocess communication • Low level: pipes, shared memory, etc • High level: MPI, ZeroMQ, etc • Lasts for “length of program”
Thread • Created out of ________ • Communicates with peers • ? • Lasts for _________
Thread • Created out of a process • Communicates with peers • ? • Lasts for _________
Thread • Created out of a process • Communicates with peers • Shared memory space* • Lasts for ________ * Not generally referred to as “shared memory”
Thread • Created out of a process • Communicates with peers • Shared memory space* • Lasts for length of code segment * Not generally referred to as “shared memory”
Process Management • We want to run multiple processes simultaneously • Let’s restrict ourselves to single terminal • So far, we can… • …suspend a process • …resume a process • What else can I do? • Change background/foreground
Background/Foreground • A terminal can run many jobs* • “Infinite” in the background • One in the foreground • By default, the job launches in the foreground • How do we get stuff in the background? * A “job” is a command we ran
Background/Foreground • At process launch • Use the ampersand • find / -name “*.txt &” • While process is running • ctrl+z to suspend • bg %n • n is the job number • Use jobs command to discover job #s • bg executes/resumes job… • …but in background
Background/Foreground • BG jobs • What happens to stdout/stderr? • What happens to stdin?
Background/Foreground • BG jobs • What happens to stdout/stderr? • Still goes to specified place • Output can get mixed with BGs and FG • What happens to stdin?
Background/Foreground • BG jobs • What happens to stdout/stderr? • Still goes to specified place • Output can get mixed with BGs and FG • What happens to stdin? • It doesn’t have access to it • How do we return stdin access to job?
Background/Foreground • BG jobs • What happens to stdout/stderr? • Still goes to specified place • Output can get mixed with BGs and FG • What happens to stdin? • It doesn’t have access to it • How do we return stdin access to job? • Return it to foreground • fg %n