OS features can be described by considering the most important resources that a modern OS manages: Memory: The OS manages a large, flat, virtual memory address space and transparently moves information between physical memory and disk and other secondary storage. File systems: The OS manages a named file space and provides both direct and sequential access as well as directory and file management. Resource naming and location: File naming allows for long, descriptive names, and the naming scheme is extended to objects such as devices, synchronization, and interprocess communication objects. Multitasking: The OS must manage processes, threads, and other units of independent, asynchronous execution. Tasks can be preempted and scheduled according to dynamically determined priorities. Communication and synchronization: The OS manages task-to-task communication and synchronization within single systems as well as communication between networked systems and with the Internet. Security and protection: The OS provides flexible mechanisms to protect resources from unauthorized and accidental access and corruption.
The original Microsoft Operating System was MS-DOS, in the 1980's. This was a simple OS with no security, no multiprocessing, and a command line interface. Apple was making inroads into Microsoft's business with its GUI based systems, and so Microsoft put a GUI on top of MS-DOS. Windows 3.0 came out in 1990, Windows 3.1 (a dramatic improvement) in But all programs ran in the same address space. Windows 95 (1995) contained most of the features of modern operating systems including virtual memory, process management, and multiprogramming. But there was still no security. Windows 95 was a commercial success, in spite of the fact that it crashed a lot. By this time Microsoft had figured out that they could not just keep adding more features to MS-DOS, so they decided to build a new operating system from scratch. The result was Windows NT (New Technology). The API system was called WIN32. Microsoft operating systems have to be backward compatible; that is, all of the applications that ran on the old Windows systems should still run on newer systems. This requires another layer in the API software to deal with this.
Windows 2000 introduced Plug-and-Play (PnP) which allowed users to install new devices on the fly. Prior to this, users would sometimes have to manually set jumper switches or dip switches, and occasionally two (or more) devices would use the same interrupt handler address, and so one interrupt would trash the other. The original release of NT was about 3 million lines of C/C++ code. Windows Vista is more than 70 million lines of code. Part of this is due to the need for backward compatibility, nothing ever gets deleted, but most of the bloat is due to the addition of new features.
There are multiple layers of system calls. At the core is the NT kernel ntoskrnl.exe, which has traditional system call interfaces, this is only used by Microsoft programmers. There are a number of subsystems that run on top of NTOS. The only subsystem that we will use is Win32. Windows can run on a number of different hardware architectures, not only different processors, but different support chipsets. In order to minimize the amount of hardware specific programming, the lowest layer of the OS is the Hardware Abstraction Layer (HAL). This layer translates all calls which deal directly with hardware into hardware accesses. Examples include the CPU itself, the Memory Management Unit, Interrupt controllers, physical devices, and the BIOS.
The registry is a special file system, (optimized for small files) attached to the NT namespace. The registry is organized into separate volumes called hives, which are like files. One of these hives is called SYSTEM. This is a file which keeps track of the system configuration. Other hives keep track of the configuration of installed software etc. Here is a list of some of the hives. In Unix systems, generally each program consults a plain text resource file when it is opened. This contains all of the configuration information. Example:.bashrc
In the Microsoft world, a system call is referred to as an Win32 API (Application Program Interface) (or a WIN64 API). If you use any of these, you should include the header file windows.h. This file contains definitions, macros, and structures for source code. As in Unix, the Win32 APIs have the same form as C function calls. The number of Win32 APIs is much larger than the number of Unix system calls. One of the major reason why the number is so much larger is that all of the graphics calls which create and manipulate windows are part of the Win32 APIs. All versions of the Windows operating systems use the Win32 APIs, but each uses a slightly different subset. The Windows API is different in many ways from the Linux POSIX (Portable Operating System Interface) API – Many system resources are represented as a kernel object identified and referenced by a handle (file descriptors and process IDs in Linux) – Kernel objects must be manipulated by Windows APIs – Objects include files, processes, threads, memory mapping, events, and many more – The Windows thread is the basic unit of execution. A process can contain one or more threads
To understand Microsoft C/C++ documentation or Microsoft sample code, you will need to understand Hungarian Notation. This is a method of naming variables (Microsoft convention). For example, the online help which describes the function ReadFile looks like this: BOOL ReadFile( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped ); A variable name consists of an optional prefix, a tag which indicates the variable type, and the variable name. The prefix is lower case, the variable name itself starts with an upper case letter.
DWORD unsigned long (stands for double word) WORD unsigned short (16 bits) BOOL boolean (Possible values are TRUE and FALSE) BYTE unsigned char LPDWORD pointer to a DWORD LPVOID Pointer to type void (a generic pointer) LPCTSTR Pointer to a const string Most Microsoft sample code includes the header file which redefines most data types.
Windows supports four file systems on directly attached devices 1.The NT file system (NTFS) is a modern file system supporting long file names, security, fault tolerance, encryption, compression, extended attributes, and support for very large files and volumes. 2.The File Allocation Table (FAT and FAT32) file systems descend from the original MS-DOS and Windows 3.1 FAT (or FAT16) file systems. FAT does not support Windows security, among other limitations. FAT is increasingly obsolete and is most frequently seen on older systems 3.The CD-ROM file system (CDFS), as the name implies, is for accessing information provided on CD-ROMs. 4.The Universal Disk Format (UDF) supports DVD drives and will ultimately supplant CDFS. The format of a file system (FAT, NTFS), as a disk volume or partition, is determined when a disk is partitioned
The full pathname of a disk file starts with a drive name, such as A: or C:. Alternatively, a full pathname, or Universal Naming Code (UNC), can start with a double backslash (\\), indicating the global root, followed by a server name and a share name to indicate a path on a network file server. The first part of the pathname, then, is \\servername\sharename. The pathname separator is the backslash (\), although the forward slash (/) can be used in API parameters, which is more convenient in C. Directory and file names cannot contain any of the ASCII characters with values in the range 131 or any of these characters: : " | ? * \ / Names can contain blanks. However, when using file names with blanks on a command line, be sure to put each file name in quotes so that the name is not interpreted as naming two distinct files. Directory and file names are case-insensitive, but they are also case-retaining, so that if the creation name is MyFile, the file name will show up as it was created, but the file can also be accessed with the name myFILE. File and directory names can be as many as 255 characters long, and pathnames are limited to MAX_PATH characters (currently 260). A period (.) separates a file's name from its extension, and extensions (usually two or three characters after the rightmost period in the file name) conventionally indicate the file's type. Thus, atou.EXE would be an executable file, and atou.C would be a C language source file. File names can contain multiple periods. A single period (.) and two periods (..), as directory names, indicate the current directory and its parent, respectively.
Batch files allow Microsoft Windows users to create a lists of commands to run in sequence. A good example of a batch file for someone who is more familiar with Windows is to think of a batch file as a shortcut. Much like a shortcut, batch files could be used to run one or more commands and/or programs through the command line. To create a batch file do the following: o open a Command Prompt window o Type edit b.bat (we are creating a batch file named b.bat) o Type in the following off echo Hello this is a test batch file pause o Save and close the file o To run the file, type in the file name
Just like all MS-DOS commands, all batch file commands are not case sensitive. %1 The percent followed by a numeric value, allows users to receive arguments a batch file. :: A way to add remarks in the batch file :LABEL By adding a colon in front of a word, such as LABEL, you create a label. This allows you to skip to certain sections of a batch file. See GOTO CALL This is used to run another batch file within a batch file. When the batch file that is called is completed, the remainder of the original batch file is completed. Note if the batch file does not exist it will give an error message CLSClear the screen ECHO Will echo a message in the batch file. However, OFF at the beginning of the batch file you'll also get each line of the batch file. Type ECHO. To create an empty line.
EXIT Exits out of the DOS window if the batch file is running from Windows. GOTO LABEL Used to go to a certain label IF Used to check for a certain condition if the condition exists PAUSE Prompt the user to press any key to continue. START Used to start an application SET [variable=[string]] Specifies the environment-variable name and value You can type SET to display environment variables. /P to prompt the user to enter a value Environment variable substitution can be as follow: %PATH:~0,-2% extract all but the last 2 characters of the PATH variable. %PATH:~-10% extract the last 10 characters of the PATH variable. %PATH:str1=str2% would expand the PATH environment variable, substituting each occurrence of str1 in the expanded result with str2 To get help for any of the batch commands: type help followed by the command. If you type help only, you will get the list of commands (but not all)
@ECHO off cls :start ECHO. ECHO 1. Print Hello ECHO 2. Print Bye ECHO 3. Print Test set choice= set /p choice=Type the number to print text:. if not '%choice%'=='' set choice=%choice:~0,1% if '%choice%'=='1' goto hello if '%choice%'=='2' goto bye if '%choice%'=='3' goto test ECHO "%choice%" is not valid please try again ECHO. goto start :hello ECHO HELLO goto end :bye ECHO BYE goto end :test ECHO TEST goto end :end You should know: To terminate a job Ctrl+C
For loop FOR variable IN (argument list) DO command Example: FOR %a IN (Andrew Bob Carol Daisy Ellen) DO echo %a FOR %a IN (*.txt) DO echo %a You should know: To run the Windows calculator use the command calc To open a new Command prompt window type start cmd taskkill and tasklist are important commands try them with care
In this exercise you are requested to create a batch file similar to question 4 of the homework related to lecture 3…. Oh yes Build a batch file that does the following: Give a menu and wait for an input 1.Launch a calculator 2.Launch a terminal window 3.Close the calculator 4.Exit
@echo off :start cls echo "Please select one of the following options:" echo " 1 - Launch a calculator" echo " 2 - Launch a terminal" echo " 3 - close calculator" echo " 4 - exit" set /P choice="You choice is: " if '%choice%' == '1' goto launchcalc if '%choice%' == '2' goto launchterminal if '%choice%' == '3' goto closecalc if '%choice%' == '4' goto end echo "Bad selection: goto start :launchcalc start calc goto start :launchterminal start cmd goto start :closecalc taskkill /IM calc.exe goto start :end