Download Operating Systems Concepts Tutorial exercises

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

VS/9 wikipedia , lookup

Criticism of Windows Vista wikipedia , lookup

Windows Phone 8.1 wikipedia , lookup

Copland (operating system) wikipedia , lookup

Windows NT startup process wikipedia , lookup

Burroughs MCP wikipedia , lookup

OS-tan wikipedia , lookup

OS/2 wikipedia , lookup

Process management (computing) wikipedia , lookup

Transcript
Operating Systems Concepts
Tutorial exercises
Exercise 2: Processes & Priorities in Windows NT
This exercise is designed to improve your grasp of what an operating system is, and what it does for you. It
should also give you some practical insight into how to find out what your computer is doing. It’s not a
bad idea at all to go thorugh this with a friend, provided that when you have finished you have both spent
some time at the keyboard exploring. You shouldn’t be able to break anything; if you manage it, blame
Microsoft and come and see me to collect a small prize.
1.
2.
Find a PC running Windows NT, with Microsoft Visual C++. Any of the Windows NT lab
machines will do (unfortunately you can’t do this exercise on Windows 95 or 98). If you’ve been
running any applications, close them before proceeding.
Use Microsoft Visual C++ to create a new project called “heartbeat”. Create a new source file
called “heart.cpp” . Enter the following source code:
(you don’t need to type this in; cut and paste it from the web:
http://www.doc.ic.ac.uk/~phjk/OperatingSystemsConcepts/Exercises/Software/heart.cpp)
#include <iostream.h>
#include <windows.h>
#include <winbase.h>
long clock()
{
LARGE_INTEGER lPerformanceFrequency;
QueryPerformanceFrequency(&lPerformanceFrequency);
LARGE_INTEGER lPerformanceCount;
QueryPerformanceCounter(&lPerformanceCount);
long countspermillisec = lPerformanceFrequency.QuadPart/1000;
return lPerformanceCount.QuadPart/countspermillisec;
}
int main()
{
int r = 0;
long lasttime = clock();
}
for (int i=0; i<100; i++) {
for (int j=0; j<100000000; j++) {
r += j;
}
cerr << "#" << i <<" took " << clock()-lasttime << " milliseconds\n";
lasttime = clock();
}
return 0;
© Paul Kelly, Imperial College 2000
1
3.
4.
5.
6.
7.
8.
9.
Build and run the heartbeat project. The program outputs a short message counting from 0 to 99,
together with a number giving the amount of time it took to execute the “j” loop. You don’t have
to wait for it to finish – you can just close the window (top right corner, marked “X””) when you
get bored.
Invoke the Task Manager. A short-cut way to do this is to hold down the control and shift keys,
and press the “Esc” key (another way is Start->Run.. then type “taskmgr”).
Use the Task Manager to answer the following questions
i)
How many applications are running on your computer?
ii)
How many processes are running on your computer?
iii)
Roughly what is your computer’s average CPU usage
iv)
Which process is using most of the CPU time? (look at the CPU column of the
“Process” tab – click on the “CPU” heading to rank the processes by CPU usage)
Now, run two instances of the heartbeat program simultaneously. This is remarkably easy:
i)
from the Visual C++ Build menu, select “Execute heartbeat.exe” (or press controlF5), as usual
ii)
while that continues to run, select the Visual C++ window again and repeat step (i)
above.
You should now have two “heartbeat” windows, both busily counting away (you may need to use
the TaskBar at the bottom of the screen to get both of them to show up on the screen at the same
time.
Arrange the two heartbeat windows side-by-side. Which one is running faster? Select the Task
Manager window. Which heartbeat is running faster now?
Select the “Process” tab in Task Manager. Use your right mouse button to select one of the
heartbeat processes. A small menu will pop up; use it to set this process’s priority to “Low”.
What happens to the heartbeat processes?
If you feel like exploring further,
i)
Use Task Manager’s “View” menu to expose more information about your processes
ii)
Have a play with Process Viewer, which comes with Visual C++. Go to the “Start”
menu, find “Programs”->”Programming Languages”->”Microsoft Visual Studio
6.0”->”Microsoft Visual Studio 6.0 Tools”->”Process Viewer”.
© Paul Kelly, Imperial College 2000
2
Background information – Applications, processes, threads
This exercise is intended to help someone with little or no experience of operating systems to begin to
understand what an OS is. When you’re happy with that, you can explore further. Much of what you see
won’t make sense til later in the course. Beware also that one of the characteristic features of software is
that the details are often unimportant and confusingly complex.
This page tries to explain a little of the unimportant detail.
Applications, processes and threads
The Windows NT kernel is the heart of the operating system. When asked to run an application program, it
creates a “virtual machine” for the program to run in – including a “virtual memory” for its code and data.
It then creates a process to execute this code. Each process starts with just one “thread” of control, but
often several threads are created so that different activities within the same application can be interleaved.
All the threads within a process share access to the same code and data.



Each application you’re currently running should be listed under the Task Manager’s Applications
tab
For each of these applications, you should be able to find a corresponding process under the
Process tab
However there are lots of processes which are not associated with an application. For example:
o System idle process: this is what the computer does whenever it has nothing else to do
(when it’s idle). It basically does nothing (though some people use this spare CPU time
to do useful things…)
o System: this process is a shell containing a collection of miscellaneous threads which
perform internal operating system functions. These threads only operate in supervisor
mode inside the operating system kernel – they never run in user mode and have no
associated memory allocation.
o Session Manager (SMSS.EXE): this process is a vestige from when the OS started
running on your machine. Its job then was to use configuration information from the
Registry to set up and check filesystems, and to start critical services such as the Win32
subsystem (CSRSS).
o Win32 subsystem (CSRSS): this process manages the display and keyboard, and supports
the “Win32” software compatibility model
o Windows Logon (WINLOGON.EXE): this handles the log-in, logout process. Once a
user is properly authenticated, an EXPLORER.EXE process is started.
You will see others – LSASS (authentication), SERVICES (device drivers etc), SPOOLSS
(background printing) etc.
Background reading, finding out more:
Gary Nutt, Operating Systems Projects using Windows NT (Addison Wesley1999)
Gives brief and very useful intro to NT’s internal structure
David A Solomon, Inside Windows NT (Second edition, Microsoft Press 1998)
The most widely-recommended source for understanding how NT works
Micorosft, Windows NT Workstation Resource Kit (Microsoft Press, 1996)
Far from brief but often useful to fill in gaps and provide details
© Paul Kelly, Imperial College 2000
3