Outline • Cross referenced Linux source code • About Lab1 • Using the Operating Systems - continued – The abstract model of computing – Resources • Files – Processes and threads – Objects Linux Source Code • Cross referenced Linux source code is available at – http://www.cs.fsu.edu/~baker/cis5930.B03/xref.html • How the system calls are implemented in Linux • Two examples – fork – execve 5/29/2016 COP4610 2 Lab1 • Built-in commands • Additional features for executing external commands • Submission • Demonstration • Grading • Honor code – You are allowed to use examples from this class – But you are not allowed to submit other’s work 5/29/2016 COP4610 3 Review: System Overview 5/29/2016 COP4610 4 Review: Using the O.S. • For a programmer, the operating system interface is most important – The functions provided by the OS • System calls in the UNIX case – Abstract resources that are available 5/29/2016 COP4610 5 Resources • A resource is any abstract machine entity that – A process must request it from the OS – The process must suspend its operations until the entity is allocated to it 5/29/2016 COP4610 6 Files • A sequential file is a named, linear stream of bytes • An open file is an abstract resource – The OS implements the abstraction by mapping bytes in the stream to blocks of information stored on the device – It has a descriptor so that OS can keep track of its status 5/29/2016 COP4610 7 Files – cont. • Files are more fundamental than other resources – They are the prevalent form by which information is stored – OS often takes the file as a primitive and then model other resource abstractions after it 5/29/2016 COP4610 8 Files – cont. • File related system calls – – – – – – open close read write lseek fcntl 5/29/2016 COP4610 9 Other Resources • Processor is a resource • Memory is a resource • I/O devices – Keyboard is a resource 5/29/2016 COP4610 10 Other Resources – cont. • UNIX treats all I/O devices as files – Provides a similar interface • open, close, read, write, seek, ioctl – Special file descriptors • 0 is the standard input • 1 is the standard output • 2 is the standard error 5/29/2016 COP4610 11 Processes • A process is a sequential program in execution – – – – The object program to be executed The data on which the program will execute Resources required by the program The threads in the process • The status of each thread’s execution – Process state – PC – Register values 5/29/2016 COP4610 12 Processes – cont. 5/29/2016 COP4610 13 Processes – cont. 5/29/2016 COP4610 14 Process States 5/29/2016 COP4610 15 Processes – cont. 5/29/2016 COP4610 16 Processes – cont. • Differences between a process and its corresponding program – A program is a static entity made up instructions – A process is a dynamic entity that executes a program on a particular set of data • It has its own status and resources – Two or more processes could be executing the same program 5/29/2016 COP4610 17 Processes – cont. 5/29/2016 COP4610 18 Threads • A thread (or lightweight process) is an execution engine component of a process; it is a basic unit of CPU utilization • It consists of: – program counter – register set – stack space 5/29/2016 COP4610 19 Threads – cont. 5/29/2016 COP4610 20 Threads executing in two processes 5/29/2016 COP4610 21 Threads – cont. • A thread shares with its peer threads its: – – – – code section data section operating-system resources collectively known as a task • A traditional or heavyweight process is equal to a task with one thread 5/29/2016 COP4610 22 UNIX Processes 5/29/2016 COP4610 23 Threads – cont. • Benefits of multithreading – Improve application responsiveness • Netscape uses multithreaded programming – – – – Use multiprocessors efficiently Improve program structure Use fewer system resources Faster to switch between threads than processes 5/29/2016 COP4610 24 Threads in a spreadsheet program 5/29/2016 COP4610 25 Disk server using threads 5/29/2016 COP4610 26 Kinds of threads • Lightweight processes – threads implemented by the OS • A process can implement user threads – threads implemented (solely) by the user – these are more efficient – but if the OS blocks one of them, they are all blocked • Kernel threads are threads that run inside the OS (a.k.a. the kernel) 5/29/2016 COP4610 27 Thread Related Functions and System Calls • POSIX Thread – pthread_create – pthread_join – pthread_exit • Solaris Thread – thr_create – thr_join – thr_exit 5/29/2016 COP4610 28 Objects • Object-oriented design models – A system is modeled as a set of autonomous entities, called objects • Each object responds to messages and interacts with other objects through message passing • Object-oriented Operating Systems – A new mechanism to specify a system • Specify the individual units of serial computation • Specify the model of interactions among units 5/29/2016 COP4610 29 Summary • Operating systems provide a virtual computing environment for application programmers – Functions provided by O.S. – Abstract resources by O.S. • Files • Processes and threads • Objects – Programmers can develop applications more efficiently 5/29/2016 COP4610 30 Recitation Tomorrow • We will first go over the requirement of Lab1 • Then we will take about how to implement the built-in commands 5/29/2016 COP4610 31