Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Operating Systems: Process API and Limited Direct Execution - TCSS 422, Lecture notes of Operating Systems

Feedback, homework questions, and class activities related to the TCSS 422 course on Operating Systems Objectives. The document covers topics such as the Process API, Limited Direct Execution, Operating System Design Goals, Virtualizing the CPU, and Linux Output Redirection. The document also includes feedback from students and examples of when to launch new processes. The document could be useful as study notes or lecture notes for students taking the TCSS 422 course or a similar course on Operating Systems.

Typology: Lecture notes

2017/2018

Uploaded on 05/11/2023

kourtney
kourtney 🇺🇸

4.8

(6)

221 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
TCSS 422 A – Winter 2018
Institute of Technology
1/10/2018
L3.1
Slides by Wes J. Lloyd
January 10, 2018 TCSS422: Operating Systems [Winter 2018]
Institute of Technology, University of Washington -Tacoma
Th e P roc ess API,
Li mit ed D irec t E xec uti on
Wes J. Ll oyd
Ins titut e o f Tech nolog y
Univer sity of Wash ingto n - Taco ma
TCSS 422: OPERATING SYSTEMS
Fee dba ck fr om 1 /8
Hom ewor k 0 Ques tio ns
Cla ss A cti vity 1
Ope rati ng sys tem de sign goal s
Cha pter 5: C L inu x Pr oce ss A PI
Cha pter 6: Li mite d Di rec t Ex ecut ion
Vir tuali zing the C PU
January 10, 2018
TCSS422: Operating Systems [Winter 2018]
Institute of Technology, University of Washington -Tacoma
L3.2
OB JECTI VE S
Pl ease com plet e th e Vi rtua l Ma chin e Su rvey if wan ting
an Ins titu te of Tec hnol ogy host ed U bunt u 16 .04 VM
htt ps:// goo .gl /fo rms/XAxxuZtut5o707I p1
January 10, 2018
TCSS422: Operating Systems [Winter 2018]
Institute of Technology, University of Washington -Tacoma
L3.3
VI RTUAL M ACHIN E SURV EY
Wha t a re f ork () a nd e xec( ) u sed for ?
for k() - spli ts a runn ing pr oces s int o two proc ess
It’ s lik e CLON ING a pro cess
exec () is use d to “ run” anot her p rogra m fro m an exis ting p roce ss
Can cont rol: sta ndard in ( stdin )
sta ndard out (stdo ut)
sta ndard err ( stde rr)
Capt ure i nput /out put to the exte rnal p rogra m.
January 10, 2018
TCSS422: Operating Systems [Winter 2018]
Institute of Technology, University of Washington -Tacoma
L3.4
SE LECTE D FEED BACK FROM 1/8
Wha t ar e ex amp les o f w hen t o la unc h new pr oces ses?
Mem ory is not s hared ( heap o r sta ck)
Cod e is sha red
For k + Exe c heap , stac k, cod e not s hared
An d lau nch new th read s?
Mem ory is shar ed (hea p and c ode)
Not s tack ba sed memo ry
January 10, 2018
TCSS422: Operating Systems [Winter 2018]
Institute of Technology, University of Washington -Tacoma
L3.5
FE EDBAC K - 2
Wha t ar e th ese thre e dif fere nt s tate s?
RUN NIN G
REA DY
BLO CKE D
January 10, 2018
TCSS422: Operating Systems [Winter 2018]
Institute of Technology, University of Washington -Tacoma
L3.6
FE EDBAC K - 3
pf3
pf4
pf5

Partial preview of the text

Download Operating Systems: Process API and Limited Direct Execution - TCSS 422 and more Lecture notes Operating Systems in PDF only on Docsity!

Institute of Technology

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma

The Process API,

Limited Direct Execution

Wes J. Lloyd

Institute of Technology

University of Washington - Tacoma

TCSS 422: OPERATING SYSTEMS

 Feedback from 1/

 Homework 0 Questions

 Class Activity 1

 Operating system design goals
 Chapter 5: C Linux Process API
 Chapter 6: Limited Direct Execution
 Virtualizing the CPU

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. OBJECTIVES

 Please complete the Virtual Machine Survey if wanting

an Institute of Technology hosted Ubuntu 16.04 VM

https://goo.gl/forms/XAxxuZtut5o707Ip January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. VIRTUAL MACHINE SURVEY

 What are fork() and exec() used for?
 fork() - splits a running process into two process
 It’s like CLONING a process
 exec() is used to “run” another program from an existing process
 Can control: standard in (stdin)
standard out (stdout)
standard err (stderr)
 Capture input/output to the external program.

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. SELECTED FEEDBACK FROM 1/

 What are examples of when to launch new processes?

 Memory is not shared (heap or stack)

 Code is shared

 Fork + Exec  heap, stack, code not shared

 And launch new threads?

 Memory is shared (heap and code)

 Not stack based memory

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. FEEDBACK - 2  What are these three different states?  RUNNING  READY  BLOCKED January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. FEEDBACK - 3

Institute of Technology

 Redirect s tdout
 ./myscript.sh > output.txt
 Redirect s tdout and std err
 ./myscript.sh > output.txt 2> output.err
 Redirect s tdout and stderr to s ame file
 ./myscript.sh > alloutput.txt 2>&
 ./myscript.sh > alloutput.txt 2>alloutput.txt

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. LINUX OUTPUT REDIRECTION

 Do I have to read the book chapter carefully or just skim

through before coming to class?

 Can a sample format submission be provided for

assignment 0?

 You went too fast

 Please interrupt!
 Throw tomatoes

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. FEEDBACK - 5 CH. 2: INTRODUCTION TO OPERATING SYSTEMS January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3.

 ABSTRACTING THE HARDWARE
 Makes programming code easier to write
 Automate sharing resources – save programmer burden
 PROVIDE HIGH PERFORMANCE
 Minimize overhead from OS abstraction
(Virtualization of CPU, RAM, I/O)
 Share resources fairly
 Attempt to tradeoff performance vs. fairness  consider
priority
 PROVIDE ISOLATION
 User programs can’t interfere with each other’s virtual
machines, the underlying OS, or the sharing of resources

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. SUMMARY: OPERATING SYSTEM DESIGN GOALS

 RELIABILIT Y

 OS must not crash, 24/7 Up-time

 Poor user programs must not bring down the system:

Blue Screen

 Other Issues:

 Energy-efficiency

 Security (of data)

 Cloud: Virtual Machines

January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. SUMMARY: OPERATING SYSTEM DESIGN GOALS - 2  ABSTRACTING THE HARDWARE  PROVIDE HIGH PERFORMANCE  PROVIDE ISOLATION  RELIABILIT Y January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. OPERATING SYSTEM DESIGN GOALS

Institute of Technology

January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3. EXEC EXAMPLE - 2 … execvp(myargs[ 0 ], myargs); // runs word count } else^ printf("this { shouldn’t print out");// parent goes down this path (main) int printf("hello, wc = wait(NULL); I am parent of %d (wc:%d) (pid:%d)\n", }^ rc, wc, (int)^ getpid()); }^ return^0 ; prompt> hello world ./p3 (pid:29383) hello, 29 107 I 1030 am childp3.c (pid:29384) hello, prompt> I am parent of 29384 (wc:29384) (pid:29383) January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3. EXEC WITH FILE REDIRECTION (OUTPUT) #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <sys/wait.h> int main(int argc, char *argv[]){ int if (rc <rc = fork(); 0 ) { // fork failed; exit fprintf(stderr, exit( 1 ); "fork failed\n"); } else if close(STDOUT_FILENO); (rc == 0 ) { // child: redirect standard output to a file open("./p4.output", O_CREAT|O_WRONLY|O_TRUNC, … S_IRWXU); January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3. FILE MODE BITS S_IRWXU read, write, execute/search by owner S_IRUSR read permission, owner S_IWUSR write permission, owner S_IXUSR execute/search permission, owner S_IRWXG read, write, execute/search by group S_IRGRP read permission, group S_IWGRP write permission, group S_IXGRP execute/search permission, group S_IRWXO read, write, execute/search by others S_IROTH read permission, others S_IWOTH write permission, others January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3. EXEC W/ FILE REDIRECTION (OUTPUT) - 2 … // now exec "wc"... char myargs[ *myargs[ 0 ] = strdup("wc"); 3 ]; // program: "wc" (word count) myargs[ myargs[ 12 ]] = strdup("p4.c");= NULL; // argument:// marks end fileof array to count } else^ execvp(myargs[ { 0 ],^ myargs);^ // parent// runs goes down this path (main)^ word^ count }^ int^ wc^ = wait(NULL); }^ return^0 ; prompt> ./p4 prompt> cat p4.output 32 109 prompt> 846 p4.c January 10, 2018 TCSS422: Operating Systems [Winter 2018] Institute of Technology, University of Washington - Tacoma L3. CH. 6: LIMITED DIRECT EXECUTION January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3.

Institute of Technology

 How does the CPU support running so many jobs

simultaneously?

 Time Sharing

 Tradeoffs:

 Performance

 Excessive overhead

 Control

 Fairness
 Security

 Both HW and OS support

is used

January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3.

VIRTUALIZING THE CPU

 What if programs could directly control the CPU / system?

January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3.

COMPUTER BOOT SEQUENCE:

OS WITH DIRECT EXECUTION

OS Program
1. Create entry for process list
2. Allocate memory for
program
3. Load program into memory
4. Set up stack with argc /
argv
5. Clear registers
6. Execute call main()
9. Free memory of process
10. Remove from process list
7. Run main()
8. Execute return from main()
Without limits on running programs,
the OS wouldn’t be in control of anything
and would “just be a library”

 With direct execution:

How does the OS stop a program from running, and switch

to another to support time sharing?

How do programs share disks and perform I/O if they are

given direct control? Do they know about each other?

With direct execution, how can dynamic memory structures

such as linked lists grow over time?

January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3.

DIRECT EXECUTION - 2

 Too little control:

 No security

 No time sharing

 Too much control:

 Too much OS overhead

 Poor performance for compute & I/O

 Complex APIs (system calls), difficult to use

January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3.

CONTROL TRADEOFF

January 10, 2018 TCSS422: Operating Systems [Spring 2017] Institute of Technology, University of Washington - Tacoma L3.

CONTEXT SWITCHING OVERHEAD

QUESTIONS