Operating System Concepts Learning Note 6 system calls

Source: Internet
Author: User
Tags terminates

Operating System Concepts Learning Note 6 system calls


System calls

system calls, usually written in C or C + +, may be provided as assembly-language instructions for the underlying tasks, such as requiring direct access to hardware.

An example of a system call:
To write a simple program that reads data from one file and copies it to another, you need the following sequence of system calls:

Get input file name:

    • Screen input Tips
    • Receive input

Get output file name:

    • Screen input Tips
    • Receive input

Open input File:

    • If the file does not exist, discard

Loop

    • Read input file
    • Write Output file

Until the read fails
Close Output File
Output the completion information to the screen
Normal End

However, general program developers have three commonly used APIs based on the application interface (API) design program:

1. Win32 API for Windows systems

2. POSIX APIs for POSIX systems (including UNIX, Linux, and Mac OS X versions)

3. Designing Java APIs that run on Java Virtual machine programs

In the background, the function that makes up the API is usually called by the application programmer to invoke the actual system.

There are three ways to pass parameters to the operating system

    1. The simplest is to pass the parameters through registers

    2. But sometimes the number of parameters is more than the register. At this point, these parameters usually exist in the block and table of memory, and the address of the block is passed through the register. Linux uses such a method.

    3. Parameters can also be pressed onto the stack and ejected through the operating system.

System Call Type

System calls can be broadly divided into five categories: Process Control, file management, device management, information maintenance, communication .

    • Process Control
      • End, give up
      • Loading execution
      • Create a process, terminate a process
      • Get process properties, set process properties
      • Wait time
      • Wait for event, wake up Event
      • Allocating and freeing memory
    • File Management
      • Create files, delete files
      • Open, close
      • Read, write, reposition
      • Get file properties, set file properties
    • Device Management
      • Request device, release device
      • Read, write, reposition
      • Get device properties, set device properties
      • Logically connecting or disconnecting devices
    • Information Maintenance
      • Read time and date, set time or date
      • Read system data, set system data
      • Read process, file, or device properties
      • Set process, file or this cup attribute
    • Communication
      • Create, delete a communication system
      • Send, accept a message
      • Delivery Status Messages
      • Link or disconnect remote devices
Process Control

The running program needs to be able to interrupt its execution normally or abnormally (end or abort)

If a system call is being used for an unhealthy interrupt execution program, or if the program runs into a problem causing an error trap, a memory information dump may occur and an error message is generated. Memory information dumps are typically written to disk and are checked and determined by the debugger (a system program that helps programmers discover and check for errors). The operating system must transfer control to the command interpreter. The command interpreter immediately reads the next command.

For interactive systems:
The command interpreter simply reads the next command because it assumes that the user will take the appropriate command to handle the error

For GUI Systems:
A pop-up alert error and a suggestion

For batch processing systems:
The command interpreter terminates the entire job and continues to the next job. In the event of an error, some systems allow the control card to indicate a specific recovery action. A control card is a batch concept that is a command that a management process executes. You can define an error level. More serious errors can be represented by more advanced error parameters. The command interpreter and the next program can use the error level to automatically determine the next action.

Executing a program or job may require another program to be loaded. This allows the command interpreter to execute a program, which can be represented by user commands, mouse stand-alone, and batch-processing commands. When the loading program terminates:

If control returns to an existing program when the new program terminates, you must save the memory image of the existing program. Therefore, a mechanism is actually created so that one program can invoke another program. If two programs continue concurrently, a new job and process is created for multi-channel execution. Some system calls are dedicated to this purpose (create process or submit job)

If you create a new job and process, you should be able to control his execution. This control requires the ability to determine and reset the properties of a process or job, including priority, maximum allowable execution time, and so on. If necessary, you can also terminate it.

Another set of system calls helps to debug programs, and many systems provide system calls to dump memory information, which helps debug programs, which can list each executed instruction that is used when executed, but only a few types of systems are available.

Many operating systems provide timesheets to represent the time at which a program executes at a certain location. The timesheet requires a tracking feature or a scheduled time interrupt. The value of the counter is recorded at each scheduled interrupt.

File Management

Common file Management system calls:

You can create and delete files first. Each system call requires a file name and may also require some properties. Create file lag, you need to open and use, may also need to read, write, reposition, and finally need to close the file.

Directories are used to organize files in the file system, and the directory requires the same action.

In addition, you need to read at least the file attributes and set file properties, and some operating systems provide more calls, such as file movement and replication.

The rest, some of which may provide APIs that take code or system calls to complete these operations, and others may only provide system programs to complete those tasks.

If a system program is called by another program, each of these armies can be considered an API by other system calls

Device Management

The program needs to use some resources to continue running when it executes, otherwise the program must wait for enough resources to be available.

Different resources controlled by the operating system can be viewed as devices, some of which are physical devices (tapes), while others can be used as abstract or virtual devices (such as files). If the system has multiple users, the user must request the device to ensure that it can be used on its own. After the device is used, the user needs to release it.

Once the device is requested (and after the device has been obtained), it can read, write, and reposition the device as if it were a file. I/O is very similar to files so that many operating systems, such as UNIX, combine the two into a file-device structure.

Information Maintenance

Many system calls are used to pass information between the user program and the operating system, and the information returned may be a system version, free memory, process information, etc.

In addition, the operating system maintains information about all processes, and some operating system calls can access this information.

Communication

There are two types of models:

Messaging model and shared memory model.
For the messaging model , the communication process exchanges messages with each other to exchange information.

For the shared memory model , the process uses the shared memories create and shared memory attach system calls to gain access to the memory areas owned by other processes.

System Program

The logical level of the computer is the hardware, which is the operating system, followed by the system program , and finally the application.

System programs provide a convenient environment for developing programs and executing programs. A small subset of the simple interfaces that indicate a system call can be quite complex.
They can be divided into:

file Management, status information, file modification, program language support, program loading and execution, communication .

Operating System Concepts Learning Note 6 system calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.