Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

Session 1.3: Operating-system services and system calls

What services an OS offers, why user programs must ask for them, and exactly how a system call crosses from user mode into the kernel and back.

Module 1 1.5 hours Theory CO1
← Before
1.2 OS structure
Monolithic → modular
You are here
1.3 Operating-system services and system calls
Module 1 · Operating Systems and Structure
Next →
1.4 Interrupts, design & booting
How the kernel gets control

Learning objectives

By the end of this session you should be able to:

  • List the OS services that help the user and those that keep the system efficient and safe.
  • Explain dual-mode operation, the mode bit and privileged instructions.
  • Trace a system call from a library function through the trap and the system-call table and back.
  • Compare the three parameter-passing methods (registers, memory block, stack).
  • Classify system calls into the six categories with Windows and UNIX examples.

Lecture notes

1. Operating-system services

An OS provides an environment for programs to run. The exact services differ between systems, but they fall into two groups: services that make life easier for the user and programmer, and services that keep the system itself efficient and safe.

Services that help the user

User interface

Command-line (CLI), graphical (GUI), touch-screen, or batch interface.

Program execution

Load a program into memory, run it, end it normally or abnormally.

I/O operations

Programs cannot drive devices directly; the OS performs I/O for them.

File-system manipulation

Create, delete, read, write, search and list files and directories; manage permissions.

Communications

Exchange information between processes on the same machine or over a network (shared memory, message passing).

Error detection

Detect and handle errors in CPU, memory, devices and user programs (e.g. divide by zero, disk read error).

Services that keep the system efficient and safe

Resource allocation

Divide CPU cycles, memory, storage and devices among concurrent users and jobs.

Logging / accounting

Keep track of which users use how much of which resource (billing, statistics, tuning).

Protection & security

Control all access to resources; authenticate users; defend against outside attacks.

All of these services are eventually reached through system calls.

2. User interfaces — the command interpreter

The command interpreter (on Linux, a shell such as bash) reads a command and executes it. Most commands are not built into the shell — rm file.txt makes the shell find the program /bin/rm, load it and pass it the argument. That way new commands can be added without changing the shell. GUIs (desktop metaphor, mouse) and touch interfaces (gestures) are friendlier, while CLIs are faster for experts and easy to automate with shell scripts — which you will write in Lab 1.

3. Dual-mode operation — why programs cannot just do it themselves

If any program could execute any instruction, a single buggy program could overwrite the kernel or another program. So the hardware provides at least two modes, selected by a mode bit:

  • Kernel mode (supervisor / privileged mode, mode bit = 0): all instructions allowed.
  • User mode (mode bit = 1): privileged instructions — I/O instructions, timer management, interrupt management, changing the mode bit — are forbidden. Trying one causes a trap to the OS.
A system call switches the CPU from user mode (bit = 1) to kernel mode (bit = 0) and back.
A system call switches the CPU from user mode (bit = 1) to kernel mode (bit = 0) and back.

Intel x86 CPUs actually have four protection rings (Linux and Windows use ring 3 for user code and ring 0 for the kernel); CPUs with virtualization support add a further mode for the hypervisor (Module 5).

4. System calls

Definition

A system call is the programmatic way a process requests a service from the kernel. It is executed by a special trap instruction (syscall on x86-64, svc on ARM) that switches the CPU to kernel mode and jumps to a fixed kernel entry point.

Even a trivial program makes many system calls. Copying one file to another (cp in.txt out.txt) needs:

  1. Get the file names (from arguments or by prompting — write to screen, read from keyboard)
  2. open the input file — abort if it does not exist
  3. creat/open the output file — abort if it cannot be created
  4. Loop: read from input, write to output, until end-of-file
  5. close both files, write a completion message, exit normally

API vs system call

Programmers rarely issue system calls directly. They use an Application Programming Interface (API) — the POSIX API on Linux/macOS (provided by the C library, libc) or the Windows API. A library function such as printf() eventually calls the write() wrapper, which loads the system-call number into a register and executes the trap. APIs are preferred because programs become portable and the API is easier to use than raw system calls.

printf("Hi")→ libc write()→ syscall #1 (trap)→ system-call table[1] → sys_write()→ driver → screen

The system-call interface uses the number as an index into a table of kernel functions, runs the function in kernel mode, and returns the result (or an error code) to user mode.

syscall_demo.c — the same output via the library and via a raw system call
#include <stdio.h>      /* printf        - C library (API)         */
#include <unistd.h>     /* write, getpid - POSIX system calls      */

int main(void)
{
    printf("Hello via printf (library)\n");
    fflush(stdout);                                   /* push the library buffer out */
    write(1, "Hello via write (system call)\n", 30);  /* fd 1 = standard output      */
    printf("My process id is %d\n", getpid());
    return 0;
}
Terminal — compile, run, and watch the system calls with strace
$ gcc syscall_demo.c -o syscall_demo
$ ./syscall_demo
Hello via printf (library)
Hello via write (system call)
My process id is 4211
$ strace -e trace=write,getpid ./syscall_demo
write(1, "Hello via printf (library)\n", 27) = 27
write(1, "Hello via write (system call)\n", 30) = 30
getpid()                                = 4212
write(1, "My process id is 4212\n", 22) = 22
+++ exited with 0 +++

Notice that printf itself is not a system call — strace shows it turned into write. The process id differs between the two runs because each run is a new process.

5. Passing parameters to system calls

A system call often needs more information than its number — a file name, a buffer address, a byte count. Three methods are used:

1 · Registers

Put the parameters in CPU registers. Fastest, but limited by the number of registers. Linux x86-64 passes up to six arguments this way.

2 · Block / table in memory

Store parameters in a block in memory and pass the block's address in a register. No limit on number or length.

3 · Stack

The program pushes parameters onto the stack; the OS pops them off. Also unlimited.

6. Types of system calls

System calls can be grouped into six major categories. The same service has different names on Windows and UNIX, but the idea is identical.

CategoryTypical operationsWindowsUNIX / Linux
Process controlcreate, terminate, load, execute, wait, allocate memoryCreateProcess()
ExitProcess()
WaitForSingleObject()
fork(), exec()
exit()
wait()
File managementcreate, delete, open, close, read, write, get/set attributesCreateFile()
ReadFile(), WriteFile()
CloseHandle()
open()
read(), write()
close()
Device managementrequest/release device, read, write, get/set attributesSetConsoleMode()
ReadConsole()
ioctl()
read(), write()
Information maintenanceget/set time, date, system data, process attributesGetCurrentProcessID()
SetTimer(), Sleep()
getpid()
alarm(), sleep()
Communicationscreate/delete connection, send/receive messages, shared memoryCreatePipe()
CreateFileMapping()
MapViewOfFile()
pipe()
shm_open()
mmap()
Protectionget/set permissions, allow/deny user accessSetFileSecurity()
InitializeSecurityDescriptor()
chmod()
umask(), chown()
Where you will use these in the lab

fork(), wait(), exit() → Lab 3 · pthread_create() → Lab 4 · shmget()/shmat() → Lab 8 · open(), read(), write(), lseek(), close() → Lab 15. Each lab exercises one row of this table.

7. System programs

Above the kernel sit system programs (system utilities) that give a convenient environment: file managers (ls, cp), status information (date, df, top), editors, compilers and debuggers (gcc, gdb), program loaders, communication tools (ssh) and background services (daemons). For most users the system programs are the operating system — but every one of them is just a user-mode program built on system calls.

VideoBytes

Operating-system services

Video coming soon

Operating-system services

Recorded by Dr. Krithika L.B. Slot m1-os-services

System calls and their types

Video coming soon

System calls and their types

Recorded by Dr. Krithika L.B. Slot m1-system-calls

Interactive lessons

Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.

Lab connection

Check your understanding

Answer each question in your own words first, then reveal the model answer.

Revealed 0
Why must I/O instructions be privileged?

If a user program could issue I/O directly it could read another user's disk blocks, overwrite the kernel on disk, or leave a device in an inconsistent state. Making I/O privileged forces every request through the OS, which checks permissions first.

Is printf() a system call? Explain.

No. printf() is a C-library (API) function that formats text in a user-space buffer. When the buffer is flushed it calls write(), whose wrapper executes the actual system-call trap.

Why do programmers use an API instead of invoking system calls directly?

Portability (the same POSIX code compiles on any POSIX system even if system-call numbers differ) and convenience (the API hides register set-up and error handling).

A system call needs eight parameters. Which passing method would you choose and why?

A block (table) in memory with its address passed in a register, or the stack — registers alone are too few (Linux on x86-64 passes at most six arguments in registers).

Classify: getpid(), pipe(), chmod(), wait(), ioctl().

getpid → information maintenance · pipe → communications · chmod → protection · wait → process control · ioctl → device management.

Key takeaways

  • OS services help users (UI, execution, I/O, files, communication, errors) and the system (allocation, accounting, protection).
  • Dual-mode hardware forces programs to request privileged work through system calls.
  • API function → trap → system-call table → kernel routine → return; parameters travel in registers, a memory block or the stack.
  • Six categories: process control, file, device, information maintenance, communications, protection.

Where this leads

A system call is one way the CPU enters the kernel — deliberately, from software. But the kernel must also take control when a device finishes, a timer expires or a program faults. Next: interrupts, the design principles behind all of this, and how the kernel gets into memory in the first place.

Continue to 1.4 — Interrupts, design issues, building and booting →