Explain It Like I'm 5API
Operating System API
What is an OS API?
What Is It?
An OS API (more commonly known as a System Call) is a way for application developers (also for automations) to interact with the computer and allow us to do anything that the OS is responsible for
IE: Read / write files, open a network socket, interact with various drivers (display graphics, print lines, open a line of communication), allocate memory, clear memory, etc
How Do We Use It?
It depends on your OS, every OS has it's own variation system calls but the structure is the same:
- The app tells the CPU to store some number on a memory node (typically on specific CPU registers)
- The app calls the system interrupt (syscall) instruction and the operating system does what the app requested
Linux Example -> Write To File / Terminal
- RAX register -> 1
- RDI register -> Output file descriptor (pointer to the destination) -> Positive integer
- RSI register -> Pointer to the content string -> Positive integer (the address of the content in RAM memory)
- RDX register -> Length of the content (size_t -> Unsigned integer -> Positive number)
- After setting these registers, we call the "int" instruction (interrupt) and the operating system does the write operation according to our parameters
If you'd like to read more about sys call options for Linux, you can read all about it here: Linux System Call Table for x86 64
You can read more about Linux based system calls here: Linux system call in Detail