Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.

Similar presentations


Presentation on theme: "Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money."— Presentation transcript:

1 Operating Systems COMP 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. 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. Most operating systems allow more than one process to be runnable at a given time.

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

4 Process Model

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

6 Process Creation Processes are created when: 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: There are two types of processes: –Foreground – interact with user –Background – run a particular function. These are called daemons. These are called daemons. Typically these handle mail, web pages, remote file requests, etc. Typically these handle mail, web pages, remote file requests, etc.

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

9 Process Termination Eventually a processes ends or terminates due to one of the following: 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. 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. One process creates a new one, which is called the child process. The process that create the new process is called the parent process. The process that create the new process is called the parent process. Windows has no hierarchy. Windows has no hierarchy.

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

12 Process States There are three 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: Examples of transitions between states:

14 Process States This model results in a scheduler, which handles which process is executing a given instant. 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 We think of the scheduler being the base of the operating system The scheduler handles interrupts and scheduling. The scheduler handles interrupts and scheduling.

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

16 Implementing Processes Each PCB has 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. Normally, each process has one thread of execution, or shortened, a thread. Many times it is desirable to have multiple threads Many times it is desirable to have multiple threads Sometimes called lightweight processes. Sometimes called lightweight processes. We use the term multithreading to refer to the fact multiple threads are running in a single process. We use the term multithreading to refer to the fact multiple threads are running in a single process.

20 Thread Model

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

22 Thread Model

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

24 Thread Model

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


Download ppt "Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money."

Similar presentations


Ads by Google