Module 2 Lesson 2 - System Calls & Programs PDF

Document Details

SharpZombie

Uploaded by SharpZombie

Polytechnic University of the Philippines

2023

Dr. Melani L. Castillo

Tags

operating systems computer science system calls programming

Summary

This document is a module on operating systems, focusing on system calls and programs. It covers various aspects such as system call examples, implementation details, and different parameter passing methods. The module is presented as part of a course at the Polytechnic University of the Philippines.

Full Transcript

PUP Sto. Tomas Campus Module in OPERATING SYSTEMS Prepared & Compiled by: DR. MELANI L. CASTILLO IT FACULTY Let us Pray! Module 2 OPERATING SYSTEM STRUCTURE Module Overview We can view an operating s...

PUP Sto. Tomas Campus Module in OPERATING SYSTEMS Prepared & Compiled by: DR. MELANI L. CASTILLO IT FACULTY Let us Pray! Module 2 OPERATING SYSTEM STRUCTURE Module Overview We can view an operating system from several vantage points. One view focuses on the services that the system provides; another, on the interface that it makes available to users and programmers; a third, on its components and their interconnections. In this chapter, we explore all three aspects of operating systems, showing the viewpoints of users, programmers, and operating system designers. We consider what services an operating system provides, how they are provided, how they are debugged, and what the various methodologies are for designing such systems. Finally, we describe how operating systems are created and how a computer starts its operating system. Objectives: At the end of this module, the student can be able to: Understand the structure of the operating system. Know the services provided by the operating system. Module 1 – OPERATING SYSTEM CONCEPTS Module 2 - Lesson 2: System Calls & System Program Lesson Objectives: To know what System call is. To understand how system call is executed. To define what System program is. System Calls Programming interface to the services provided by the OS Typically written in a high-level language (C or C++) Mostly accessed by programs via a high-level Application Programming Interface (API) rather than direct system call use Three most common APIs are Win32 API for Windows, POSIX API for POSIX-based systems (including virtually all versions of UNIX, Linux, and Mac OS X), and Java API for the Java virtual machine (JVM) Note that the system-call names used throughout this text are generic System Call Example If a process is running a user program in user mode and needs a system service, such as reading data from a file, it has to execute a trap instruction to transfer control to the operating system. The operating system then figures out what the calling process wants by inspecting the parameters. Then it carries out the system call and returns control to the instruction following the system call. In a sense, making a system call is like making a special kind of procedure call—only system calls enter the kernel and procedure calls do not. Steps in System calls System calls are performed in a series of steps. To make this concept clearer, In preparation for calling the read library procedure, which actually makes the read system call, the calling program first prepares the parameters, for instance by storing them in a set of registers that by convention are used for parameters. The first and third parameters are passed by value, but the second parameter is a reference, meaning that the address of the buffer is passed, not the contents of the buffer. Then comes the actual call to the library procedure (step 4). This instruction is the normal procedure-call instruction used to call all procedures. Example of System Calls System call sequence to copy the contents of one file to another file Example of Standard API System Call Implementation Typically, a number associated with each system call System-call interface maintains a table indexed according to these numbers The system call interface invokes the intended system call in OS kernel and returns status of the system call and any return values The caller need know nothing about how the system call is implemented Just needs to obey API and understand what OS will do as a result call Most details of OS interface hidden from programmer by API Managed by run-time support library (set of functions built into libraries included with compiler) API – System Call – OS Relationship System Call Parameter Passing Often, more information is required than simply identity of desired system call Exact type and amount of information vary according to OS and call Three general methods used to pass parameters to the OS Simplest: pass the parameters in registers In some cases, may be more parameters than registers Parameters stored in a block, or table, in memory, and address of block passed as a parameter in a register This approach taken by Linux and Solaris Parameters placed, or pushed, onto the stack by the program and popped off the stack by the operating system Block and stack methods do not limit the number or length of parameters being passed Parameter Passing via Table Types of System Calls Process control create process, terminate process end, abort load, execute get process attributes, set process attributes wait for time wait event, signal event allocate and free memory Dump memory if error Debugger for determining bugs, single step execution Locks for managing access to shared data between processes Types of System Calls File management create file, delete file open, close file read, write, reposition get and set file attributes Device management request device, release device read, write, reposition get device attributes, set device attributes logically attach or detach devices Types of System Calls (Cont.) Information maintenance get time or date, set time or date get system data, set system data get and set process, file, or device attributes Communications create, delete communication connection send, receive messages if message passing model to host name or process name From client to server Shared-memory model create and gain access to memory regions transfer status information attach and detach remote devices Types of System Calls (Cont.) Protection Control access to resources Get and set permissions Allow and deny user access Examples of Windows and Unix System Calls Standard C Library Example C program invoking printf() library call, which calls write() system call Example: MS-DOS Single-tasking Shell invoked when system booted Simple method to run program No process created Single memory space Loads program into memory, overwriting all but the kernel Program exit -> shell At system startup running a program reloaded Example: FreeBSD Unix variant Multitasking User login -> invoke user’s choice of shell Shell executes fork() system call to create process Executes exec() to load program into process Shell waits for process to terminate or continues with user commands Process exits with: code = 0 – no error code > 0 – error code System Programs System programs provide a convenient environment for program development and execution. They can be divided into: File manipulation Status information sometimes stored in a File modification Programming language support Program loading and execution Communications Background services Application programs Most users’ view of the operation system is defined by system programs, not the actual system calls System Programs Provide a convenient environment for program development and execution Some of them are simply user interfaces to system calls; others are considerably more complex File management - Create, delete, copy, rename, print, dump, list, and generally manipulate files and directories Status information Some ask the system for info - date, time, amount of available memory, disk space, number of users Others provide detailed performance, logging, and debugging information Typically, these programs format and print the output to the terminal or other output devices Some systems implement a registry - used to store and retrieve configuration information System Programs (Cont.) File modification Text editors to create and modify files Special commands to search contents of files or perform transformations of the text Programming-language support - Compilers, assemblers, debuggers and interpreters sometimes provided Program loading and execution- Absolute loaders, relocatable loaders, linkage editors, and overlay-loaders, debugging systems for higher-level and machine language Communications - Provide the mechanism for creating virtual connections among processes, users, and computer systems Allow users to send messages to one another’s screens, browse web pages, send electronic-mail messages, log in remotely, transfer files from one machine to another System Programs (Cont.) Background Services Launch at boot time Some for system startup, then terminate Some from system boot to shutdown Provide facilities like disk checking, process scheduling, error logging, printing Run in user context not kernel context Known as services, subsystems, daemons Application programs Don’t pertain to system Run by users Not typically considered part of OS Launched by command line, mouse click, finger poke End of Lesson 2 Any Questions References : Nutt, G. (2009), Operating Systems: A Modern Perspective, 3rd Edition, Pearson Addison-Wesley Inc, Boston , Massachusetts. Silberschatz, A., Galvin, P., and Gagne, G.(2018). ―Operating ‗System Concepts‖, 10th ed. John Wiley and ―Sons Inc. Stallings, Wiliam. (2018). ―Operating Systems: Internals and Design Principles‖ 9th ed. Pearson Education Inc. Harris, J. Archer., ―Schaum‘s Outline of Theory and Problems of Operating Systems. McGraw Hill Companies Inc., 2002 https://ssmengg.edu.in/weos/weos/upload/EStudyMaterial/Cse/6th%20sem/Operating%20system/operating%20system.pdf https://techterms.com/definition/operating_system https://www.geeksforgeeks.org/types-computer-memory-ram-rom/ https://www.tutorialspoint.com/operating_system/operating_system_tutorial.pdf https://www.geeksforgeeks.org/types-of-operating-systems/ What is an Operating System? Goals & Functions of Operating System | Concept Simplified by Animation - YouTube Lesson Assessment Answer the following review questions: 1. Explain at least one structure of an Operating System? 2.How do OS debug error in a program? 3.How can you improve the performance of your computer? Lesson Synthesis Lesson Assignment: Assignment#1 Research at least 1.Do advance 3 Operating study of Modulesystem 2 – Lesson 2 Compare them 2.Be ready for based on thenext a recitation following: meeting. Features & Functions Advantages and Disadvantages

Use Quizgecko on...
Browser
Browser