Process and threads
-
Upload
merwin-arthur-guinto -
Category
Data & Analytics
-
view
123 -
download
0
Transcript of Process and threads
CHAPTER 2-PROCESSES AND
THREADS
REPORTED BY: GUINTO, MERWIN ARTHUR M.MIT 596-OPERATING SYSTEMSREFERENCE:MODERN OPERATING SYSTEMS BY TANENBAUM
PROCESSES
All modern computers often do several things at the same time.People used to working with personal computers may not be fully aware of this fact.
Consider a user PC.When the system is booted, many processes are secretly started, often unknown to the user. For example, a process may be started up to wait for incoming e-mail.
PROCESSES
Another process may run on behalf of the anti-virus program to check periodically if any new virus definition are available.In addition, explicit user processes may be running, printing files and burning a CD-ROM, all while the user is surfing the web. All this activity has to be managed, and a multiprogramming system supporting multiple processes comes in very handy here.
PROCESSES
To check the processes that run on the background you can Press Window key + R
Then type msconfig On the processes you will all of the
processes running on your computer
THE PROCESS MODEL
In this model, all the runnable software on the computer, sometimes
including the operating system, is organized into a number of sequential
processes, or just processes for short..
THE PROCESS MODEL
A process is just an instance of an executing program, including the current values of the program counter, registers, and variables
THE PROCESS MODEL
Conceptually, each process has its own virtual CPU. In reality, of course, the real CPU switches back and forth from process to process, but to understand the system, it is much easier to think about a collection of processes running in (pseudo) parallel than to try to keep track of how the CPU switches from program to program
THE PROCESS MODEL
THE PROCESS MODEL
The difference between a process and a program is subtle, but crucial. An analogy may help here. Consider a culinary-minded computer scientist who is baking a birthday cake for his daughter. He has a birthday cake recipe and a kitchen well stocked with all the input: flour, eggs, sugar, extract of vanilla, and so on.
PROCESS CREATION
There are four principal events that cause processes to be created:
1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to create a new process. 4. Initiation of a batch job.
PROCESS CREATION
When an operating system is booted,typically several processes are created. Some of these are foreground processes, that are processes that interact with (human) users and perform work for them.
i.e. Compilers,Word Processors,Browsers
PROCESS CREATION
Others are background processes, which are not associated with particular users, but instead have some specific function.
Processes that stay in the background to handle some activity such as e-mail, Web pages, news, printing, and so on are called DAEMONS.
PROCESS CREATION
Often a running process will issue system calls to create one or more new processes to help it do its job. Creating new processes is particularly useful when the work to be done can easily be formulated in terms of several re-lated, but otherwise independent interacting processes. For example, if a large amount of data is being fetched over a network for subsequent processing, it may be convenient to create one process to fetch the data and put them in a shared buffer while a second process removes the data items and processes them. On a mul-tiprocessor, allowing each process to run on a different CPU may also make the job go faster.
PROCESS TERMINATION
After a process has been created, it starts running and does whatever its job is.
However, nothing lasts forever, not even processes. Sooner or later the new process will terminate, usually due to one of the following conditions: 1. Normal exit (voluntary). 2. Error exit (voluntary). 3. Fatal error (involuntary). 4. Killed by another process (involuntary).
PROCESS TERMINATION
Most processes terminate because they have done their work.
The second reason for termination is that the process discovers a fatal error.
PROCESS TERMINATION
The third reason for termination is an error caused by the process, often due to a program bug. Examples include executing an illegal instruction, referencing non existent memory, or dividing by zero.
The fourth reason a process might terminate is that the process executes a system call telling the operating system to kill some other process.
PROCESS TERMINATION
PROCESS HIERARCHIES
In some systems, when a process creates another process, the parent process and child process continue to be associated in certain ways. The child process can itself create more processes, forming a process hierarchy.
Note that unlike plants and animals that use sexual reproduction, a process has only one parent (but zero, one, two, or more children).
PROCESS STATES
PROCESS STATES
THREADS
In traditional operating systems, each process has an address space and a single thread of control. In fact, that is almost the definition of a process. Nevertheless, there are frequently situations in which it is desirable to have, multiple threads of control in the same address space running in quasi-parallel, as though they were (almost) separate processes (except for die shared address space).
THREAD USAGE
Why would anyone want to have a kind of process within a process?
It turns out there are several reasons for having these miniprocesses, called threads.
THREAD USAGE
The main reason for having threads is that in many applications, multiple activities are going on at once. Some
of these may block from time to time. By decomposing
such an application into multiple sequential threads that run in quasi-
parallel, the programming model becomes simpler.
SCHEDULING
Back in the old days of batch systems with input in the form of card images on a magnetic tape, the scheduling algorithm was simple: just run the next job on the tape. With multiprogramming systems, the scheduling algorithm became more complex because there were generally multiple users waiting for service.
SCHEDULING
Categories of Scheduling Algorithms1.Batch
2.Inter active
3.Real time
SCHEDULING
SCHEDULING IN BATCH SYSTEMS FIRST COME FIRST SERVED SHORTEST JOB FIRST SHORTEST REMAINING TIME NEXT
SCHEDULING IN INTERACTIVE SYSTEMS Round-Robin Scheduling -One of the oldest, simplest, fairest, and most widely used algorithms is round robin. Each process is assigned a time interval, called its quantum, during which it is allowed to run. If the process is still running at the end of the quantum, the CPU is preempted and given to another process. If the process has blocked or fin-
SCHEDULING IN INTERACTIVE SYSTEMS Priority Scheduling On a PC with a single owner, there may be multiple processes, some of them more important than others. For example, a daemon process sending elec-tronic mail in the background should be assigned a lower priority than a process displaying a video film on the screen in real time.
SCHEDULING IN INTERACTIVE SYSTEMS Shortest Process NextBecause shortest job first always produces the minimum average response time for batch systems, it would be nice if it could be used for interactive proc-esses as well.
SCHEDULING IN INTERACTIVE SYSTEMS
Guaranteed Scheduling A completely different approach to scheduling is to
make real promises to the users about performance and then live up to those promises. One promise that is realistic to make and easy to
live up to is this: If there are n users logged in while you are
working, you will receive about 1/n of the CPU power. Similarly, on a
single-user system with n processes running, all things being equal, each one should get \/n of the
CPU cycles. That seems fair enough.
SCHEDULING IN INTERACTIVE SYSTEMS Lottery Scheduling The basic idea is to give processes lottery tickets for various system resources, such as CPU time. Whenever a scheduling decision has to be made, a lottery ticket is chosen at random, and the process holding that ticket gets the resource. When applied to CPU scheduling, the system might hold a lottery 50 times a second, with each winner getting 20 msec of CPU time as a prize.
SCHEDULING IN INTERACTIVE SYSTEMS Fair-Share Scheduling
To prevent this situation, some systems take into account who owns a process before scheduling it. In this model, each user is allocated some fraction of the CPU and the scheduler picks processes in such a way as to enforce it. Thus if two users have each been promised 50% of the CPU, they will each get that, no matter how many processes they have in existence.
SCHEDULING IN REAL TIME SYSTEMS A real-time system is one in which
time plays an essential role. Typically, one or more physical devices external to the computer generate stimuli, and the computer must react appropriately to them within a fixed amount of time.
SCHEDULING IN REAL TIME SYSTEMS Real-time systems ate generally
categorized as hard real time, meaning there are absolute deadlines that must be met, or else, and soft real time, meaning that missing an occasional deadline is undesirable, but nevertheless tolerable.
The Dining Philosophers Problem
The Dining Philosophers Problem The life of a philosopher consists of
alternate periods of eating and thinking. (This is something of an abstraction, even for philosophers, but the other activities are irrelevant here.) When a philosopher gets hungry, she tries to acquire her left and right forks, one at a time, in either order. If successful in acquiring two forks, she eats for a while, then puts down the forks, and continues to think.