22
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof. Mark Corner and Prof. Emery Berger’s OS course at Umass Amherst Assistant Professor, University of Maryland Baltimore County [email protected] http://www.csee.umbc.edu/~nilanb/teaching/ 421/

CMSC421: Principles of Operating Systems

  • Upload
    keelia

  • View
    51

  • Download
    0

Embed Size (px)

DESCRIPTION

CMSC421: Principles of Operating Systems. Nilanjan Banerjee. Assistant Professor, University of Maryland Baltimore County [email protected] http://www.csee.umbc.edu/~nilanb/teaching/421/. Principles of Operating Systems - PowerPoint PPT Presentation

Citation preview

Page 1: CMSC421: Principles of Operating Systems

1

CMSC421: Principles of Operating Systems

Nilanjan Banerjee

Principles of Operating SystemsAcknowledgments: Some of the slides are adapted from Prof. Mark Corner

and Prof. Emery Berger’s OS course at Umass Amherst

Assistant Professor, University of MarylandBaltimore [email protected]

http://www.csee.umbc.edu/~nilanb/teaching/421/

Page 2: CMSC421: Principles of Operating Systems

2

Announcements

• Readings from Silberchatz [4th chapter]• Project 1 is out• Homework 2 would be out end of this week• Homework 1 grades are out

Page 3: CMSC421: Principles of Operating Systems

3

POSIX Signals

Linux kernelProcess 1 Process 2

Register a signal

deliver a signal

Name Description Default ActionSIGINT Interrupt character typed terminate processSIGQUIT Quit character typed (^\) create core imageSIGKILL kill -9 terminate processSIGSEGV Invalid memory reference create core imageSIGPIPE Write on pipe but no reader terminate processSIGALRM alarm() clock ‘rings’ terminate processSIGUSR1 user-defined signal type terminate processSIGUSR2 user-defined signal type terminate process

Page 4: CMSC421: Principles of Operating Systems

4

signals

• int kill( pid_t pid, int signo );– Send a signal to a process with a process id

• signal(<signal name>, <pointer to handler>)– Handle a maskable signal in your code

Page 5: CMSC421: Principles of Operating Systems

5

Message Passing Using Sockets

• A socket is defined as an endpoint for communication

• Concatenation of IP address and port

• The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8

• Communication consists between a pair of sockets

Page 6: CMSC421: Principles of Operating Systems

6

Message Passing Using Sockets

Page 7: CMSC421: Principles of Operating Systems

7

Concept of Remote Procedure calls

Remote procedure call (RPC) abstracts procedure calls between processes on networked systems

Stubs – client-side proxy for the actual procedure on the server

The client-side stub locates the server and marshalls the parameters

The server-side stub receives this message, unpacks the marshalled parameters, and performs the procedure on the server

Page 8: CMSC421: Principles of Operating Systems

Execution of RPC

Page 9: CMSC421: Principles of Operating Systems

9

A Step back: Definition of a Process

One or more threads running in an address space

Page 10: CMSC421: Principles of Operating Systems

10

What is an address space?

A collection of data and code for the program organized in an memory (addressable) region

Page 11: CMSC421: Principles of Operating Systems

11

Why do we need processes?

A process (with a single thread) supports a serial flow of execution

Is that good enough for all purposes? What if something goes wrong in one process? What if something takes a long amount of time in one

process? What if we have more than one user?

Page 12: CMSC421: Principles of Operating Systems

12

Processes Vs Threads

Both abstractions are very important They can provide parallel programming & concurrency They can hide latency from the end user Maximize CPU utilization Handle multiple, asynchronous events

But they support different programming styles, have different performances

Page 13: CMSC421: Principles of Operating Systems

13

What is difference between Process and Threads

The execution context of the process are (Program Counter, registers), address space, files, mmaped regions etc.

Page 14: CMSC421: Principles of Operating Systems

14

What is difference between Process and Threads

Threads share an address space. They have same files, sockets etc.

They have their own stack, program counters, registers, and stack specific data

Page 15: CMSC421: Principles of Operating Systems

15

Creating Threads

UNIX Pthreads (POSIX threads) Pthread_create() --- creating a thread Pthread_join() --- wait for thread to finish

Lets see a demonstration of using pthreads.

Page 16: CMSC421: Principles of Operating Systems

16

Scheduling

One-one (linux)Many-one (Green Threads)

Many-many (Window-NT)

Page 17: CMSC421: Principles of Operating Systems

17

When to use Threads and When to use processes

Processes or Threads Performance? Flexibility/Ease-of-use Robustness

Simple Scheduling OS has a list of Threads and schedules them similar to

Processes. In Linux, threads/processes treated similarly Chooses one of the threads and loads them to be run Runs them for a while, runs another.

Page 18: CMSC421: Principles of Operating Systems

18

How does it work in Linux Linux refers to them as tasks rather than threads

Thread creation is done through clone() system call

clone() allows a child task to share the address space of the parent task (process)

struct task_struct points to process data structures (shared or unique)

Page 19: CMSC421: Principles of Operating Systems

19

Threads Vs Processes

Processes or Threads Performance? Flexibility/Ease-of-use Robustness

Simple Scheduling OS has a list of Threads and schedules them similar to

Processes. In Linux, threads/processes treated similarly Chooses one of the threads and loads them to be run Runs them for a while, runs another.

Page 20: CMSC421: Principles of Operating Systems

20

Flexibility/Ease of use?

Process are more flexible Easy to spawn processes, I can ssh into a server and

spawn a process Can communicate over sockets= distributes across

machines

Threads Communicate using memory – must be on the same

machine Requires thread-safe code

Page 21: CMSC421: Principles of Operating Systems

21

Robustness

Process are more robust Processes are separate or sandboxed from other

processes If one process dies, no effect on other processes

Threads If one thread crashes, whole process terminates Since there is sharing, there are problems with using the

stack efficiently

Page 22: CMSC421: Principles of Operating Systems

22

An in-class discussion