eolas/zk/Operating_system_API.md

41 lines
1.4 KiB
Markdown
Raw Normal View History

2024-07-17 07:00:04 +01:00
---
title: Operating_system_API
2024-07-17 08:00:04 +01:00
tags: [operating-systems]
2024-07-17 07:00:04 +01:00
created: Wednesday, July 17, 2024
---
# Operating system API
2024-07-17 08:00:04 +01:00
2024-07-20 11:00:04 +01:00
A user can interact with the operating system either via the GUI or the
[shell](Intro_to_the_Unix_shell.md). Both ultimately access the OS via the shell
since the UI is an abstraction layer of the shell. When _programs_ interact with
the operating system they use the **operating system's API**.
2024-07-17 08:00:04 +01:00
Every OS has an API. This specification details how a program should interact
with the OS, exposing functions, properties and data types.
Whether using the GUI or a terminal emulator, the shell translates the user's
commands into API calls. The API the invokes internal operating system code to
perform the action.
![OS API diagram](../img/OS-api.svg)
## Example: opening a file
2024-07-20 11:00:04 +01:00
A user can use a file explorer and the mouse to open a file. Or they can open
the file by invoking it from the terminal.
A running application doesn't have to do this. If it's remit includes opening
files, it can do so by calling the OS API.
2024-07-17 08:00:04 +01:00
On a Unix-like system the applicaton would use the `open` API function to open
the file:
```
open("foo.txt", 0_WRONLY|0_CREAT)
```
This command makes the action write-only and creates the file because it does
not yet exist. When the user opens a file in their File Explorer, the
application translates their graphical actions into this API call.