a) Discuss the key functions of an operating system, and how these functions make it possible for computer applications to effectively utilize computer system resources.
b) Compare and contrast the Windows API and the POSIX API and briefly explain how these APIs can be applied in systems programming.
c) Write a C/C++ program to create a file in a specified folder of the Windows file system, and write some text to the file. Compile and run the program and copy the source code into your answer booklet.
a) An operating system is a program on which application programs are executed and acts as a communication bridge (interface) between the user and the computer hardware.
The main task an operating system carries out is the allocation of resources and services, such as the allocation of memory, devices, processors, and information. The operating system also includes programs to manage these resources, such as a traffic controller, a scheduler, a memory management module, I/O programs, and a file system.
Following are some of the important functions of an operating system.
b) Traditionally, all Unix programming was system-level programming. Unix systems historically did not include many higher-level abstractions. Even programming in a development environment such as the X Window System exposed in full view the core Unix system API. Consequently, it can be said that this book is a book on Linux programming in general. But note that this book does not cover the Linux programming environment —for example, there is no tutorial on the make on these pages. What is covered in the system programming API exposed on a modern Linux machine?
We can compare and contrast system programming with application programming, which differs in some important aspects but are quite similar in others. System programming’s hallmark is that the system programmer must have an acute awareness of the hardware and the operating system on which they work. Where system programs interface primarily with the kernel and system libraries, application programs also interface with high-level libraries. These libraries abstract away the details of the hardware and operating system. Such abstraction has several goals: portability with different systems, compatibility with different versions of those systems, and the construction of higher-level toolkits that are easier to use, more powerful, or both. How much of a given application uses system versus high-level libraries depends on the level of the stack at which the application was written. Some applications are written exclusively to higher-level abstractions. But even these applications, far from the lowest levels of the system, benefit from a programmer with knowledge of system programming. The same good practices and understanding of the underlying system inform and benefit all forms of programming.
c) // C++ implementation to create a file
#include <bits/stdc++.h>
using namespace std;
// Driver code
int main()
{
// fstream is Stream class to both
// read and write from/to files.
// file is object of fstream class
fstream file;
// opening file "Gfg.txt"
// in out(write) mode
// ios::out Open for output operations.
file.open("Gfg.txt",ios::out);
// If no file is created, then
// show the error message.
if(!file)
{
cout<<"Error in creating file!!!";
return 0;
}
cout<<"File created successfully.";
// closing the file.
// The reason you need to call close()
// at the end of the loop is that trying
// to open a new file without closing the
// first file will fail.
file.close();
return 0;
}
Comments
Leave a comment