System Programming 101: A Newcomer's Introduction
Table of contents
- 1. What is the difference Between Application and System Programming?
- 2. What is an API? Why are APIs So Important?
- 3. What are Protection Rings?
- 4. Examples of What Cannot Be Done in User Space
- 5. What is a System Call?
- 6. Managing Processes in Unix
- 7. What is POSIX? Why is POSIX Useful?
- 8. Is Windows POSIX Compliant?
Recently, I explored system programming, a crucial yet often overlooked field essential for computer functionality, and here’s what I’ve learned so far:
1. What is the difference Between Application and System Programming?
Application programming focuses on creating software that performs specific tasks for users, like word processors or games. System programming, on the other hand, deals with writing software that manages and operates computer hardware, enabling applications to run. Think of it as the difference between building a house (application programming) and constructing the tools needed to build that house (system programming). In other words, System programming is building software for the software.
2. What is an API? Why are APIs So Important?
An API, or Application Programming Interface, is a set of rules and protocols for building and interacting with software applications. It allows different software programs to communicate with each other. APIs are essential because they enable the integration of different systems, allowing developers to use pre-built functions to avoid reinventing the wheel, which accelerates development and ensures consistency.
3. What are Protection Rings?
Protection rings are a method of structuring a computer system to provide different levels of access to its resources. They are typically visualized as concentric circles, with the innermost ring (Ring 0) having the most privileges, often used by the operating system kernel. As you move outward to Ring 1, Ring 2, and so on, the privilege levels decrease. User applications usually run in Ring 3, where they have the least privilege, which helps protect the system from accidental or malicious interference. The Linux model simplifies this hierarchy to just two levels called user and kernel space
4. Examples of What Cannot Be Done in User Space
In user space, applications cannot directly access hardware or execute privileged instructions. For example, they cannot directly manage memory allocation or interact with hardware devices like the CPU or hard drive. These tasks require the higher privileges found in kernel space (Ring 0).
5. What is a System Call?
System calls are a specific set of APIs provided by the Kernel to request resources to the Kernel. It acts as a bridge between the low-level functions performed by the kernel and the higher-level operations needed by applications. For example, when an application needs to read a file from the disk, it uses a system call to ask the kernel to perform this task.
6. Managing Processes in Unix
In Unix, several system calls are used to manage processes. These include:
fork()
: Creates a new process by duplicating the existing one.exec()
: Replaces the current process image with a new one.wait()
: Waits for a process to change state, typically used to wait for a child process to finish.exit()
: Terminates a process.
7. What is POSIX? Why is POSIX Useful?
POSIX, or Portable Operating System Interface, is a set of standards that ensures compatibility between different operating systems. It defines a consistent API for Unix-like systems, which helps developers write portable code that can run on various systems without modification. This standardization is incredibly beneficial for ensuring software compatibility and portability.
8. Is Windows POSIX Compliant?
Windows is not fully POSIX compliant. However, it provides a POSIX-compliant subsystem called the Windows Subsystem for Linux (WSL), which allows users to run a GNU/Linux environment directly on Windows. This capability bridges the gap and provides some level of compatibility, making it easier for developers who rely on POSIX standards to work on Windows.
This journey into system programming has been eye-opening, revealing how critical these lower-level operations are for the smooth functioning of our daily applications. It’s like discovering the gears inside a clock—intricate and essential.
Subscribe to my newsletter
Read articles from Sagar Mohanty directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sagar Mohanty
Sagar Mohanty
Developer from India experienced in C#, React, and Python. Diving into the world of Go, and loving every bit of the simple yet powerful language.