1 / 25

Operating Systems COMP 4850/CISG 5550

Operating Systems COMP 4850/CISG 5550. Processes Introduction to Threads Dr. James Money. Processes. A process is the abstraction of a running program. This includes the code, associated memory, among other items.

indiya
Télécharger la présentation

Operating Systems COMP 4850/CISG 5550

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operating SystemsCOMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money

  2. Processes • A process is the abstraction of a running program. This includes the code, associated memory, among other items. • Most operating systems allow more than one process to be runnable at a given time.

  3. Process Model • A process is an executing program • We mentally think of the process having a virtual CPU. • However, in reality, the CPU switches between active processes in a rapid fashion. • This switching is called multiprogramming.

  4. Process Model

  5. Process Creation • We need a way to create and terminate a process • There are a number of ways a process is created.

  6. Process Creation • Processes are created when: • System initialization • Execution of a process creation system call by a running process • A user request to create a new process • Initiation of a batch job

  7. Types of processes • There are two types of processes: • Foreground – interact with user • Background – run a particular function. • These are called daemons. • Typically these handle mail, web pages, remote file requests, etc.

  8. Creating Processes • UNIX: • fork() • Followed by exec() • Windows • CreateProcess • Separate address space for each process

  9. Process Termination • Eventually a processes ends or terminates due to one of the following: • Normal, voluntary exit • Error exit, voluntary • Fatal error, involuntary • Killed by another process, involuntary

  10. Process Hierarchies • When processes create new processes, you get a hierarchy in UNIX, which also called a process group. • One process creates a new one, which is called the child process. • The process that create the new process is called the parent process. • Windows has no hierarchy.

  11. Process States • Many times processes interact with other process • Example: • cat chapter1 chapter2 chapter3|grep tree • Grep may run before cat starts it’s output • This state is called blocked.

  12. Process States • There are three states • Running – using the CPU • Ready – runnable, but stopped • Blocked – waiting for an external event to occur

  13. Process States • Examples of transitions between states:

  14. Process States • This model results in a scheduler, which handles which process is executing a given instant. • We think of the scheduler being the base of the operating system • The scheduler handles interrupts and scheduling.

  15. Implementing Processes • To implement, we use a process table, with one entry per process. • Each entry is a called a process control block.

  16. Implementing Processes • Each PCB has • Process state • Program counter • Stack pointer • Memory allocations • Open files • Scheduling information • Other info needed for running

  17. PCBs

  18. Handling Interrupts

  19. Threads • Normally, each process has one thread of execution, or shortened, a thread. • Many times it is desirable to have multiple threads • Sometimes called lightweight processes. • We use the term multithreading to refer to the fact multiple threads are running in a single process.

  20. Thread Model

  21. Thread Model • Different threads != different processes • No memory protection in threads, so they can wipe other threads memory values • Threads have unique: • Program counters • Registers • Stack • State information

  22. Thread Model

  23. Thread Model • Threads have three states like processes, plus a final one: • Running • Blocked • Ready • And terminated • Threads have independent stacks

  24. Thread Model

  25. Thread Functions • thread_create() – create a new thread from a function pointer • thread_exit() – exit a thread • thread_wait() – wait for a thread to finish • thread_yield() – voluntarily give up CPU to other threads

More Related