Systems Programming

March 23, 2025
cc++systems

what is systems programming

systems programming simply focuses on building low level software that interactes with the operating system and the hardware. systems programming tasks include OS development, device drivers, embedded systems etc.

lower lower into systems programming are system calls. the operating system executes application simultaneously while also providing the resources needed for those applications. the operating system does this by dividing the hardware resources between the applications.the os is responsible for managing the applications and their acess to the hardware resources.

to accomplish this the os provides API that the applications can leverage to accomplish their tasks. under the hood the API's make calls to the os using ABIs(application binary interfaces) called system calls.

different types of system calls

almost every appication that executes on a POSIX-compliant os must make a couple of system calls.

console input/output

outputting to stdout and stderr is accomplished by performing a system call that asks the operating system to deliver a character buffer to these output devices.

when writes to or read from the console io. the programming language used makes calls through an API which instructs the operating system to transfer a character buffer to a device that manages stdout or stderr. this could end up making another system call to display the character buffer to the screen.

memory allocation

at first most applications are given global and stack memory resources, along with a small heap of memory that the application can use when calls to functions such as malloc() and free() are made.

when given head memory runs out the application makes systems calls to the os for more memory. on systems with limited RAM when a request of more memory is made the os takes memory from other applications that aren't currently executing.

file input/output

reading and writing to files involves system calls. on POSIX systems, these operations don’t always target actual storage files—they may interact with devices like consoles or virtual files such as /dev/random. these files behave like regular files but serve special purposes, like returning random data when read.

networking

networking uses system calls too. On POSIX systems, you work with sockets—a programming interface to the network hardware. although networking is a complex subject, the operating system handles most of the complexity, and developers only need to use a simple socket API to send and receive data.

time

even getting the current date and time requires system calls. the OS retrieves the time from a dedicated hardware chip, which continues working even when power is lost (thanks to a battery). however, some high-resolution timers are built into the CPU and don’t require system calls. these timers are super fast and useful for measuring tiny performance differences, but their values alone aren’t meaningful unless compared.

threads and processes

creating multiple tasks at the same time involves system calls too. a process is a running instance of a program with its own resources like memory. a thread is like a mini-process that shares resources with others in the same program. threads are useful for parallel tasks and are lighter than full processes.