Operating System Services-- the linux example

 

Ordinary user processes are offered a variety of services by operating systems. Modern operating systems require the use of their services for many purposes-- there is no other way. For example, if a program wants to open a file, it can't. The operating system can, and will be happy to do it for the program. All the program has to do is ask. That's called making a system call, to the "file open" system service. Older operating systems did not enforce the "we'll take charge of the system operations around here!" stricture. MS-DOS offered such services, but a program could go around them and do the job on its own. More serious operating systems like unix and later ones like windows took over such tasks to centralize them and stem the tendency toward anarchy and instability that this resulted. The programs (upper grey rectangles) go through the operating system (lower gray layer) to access disks and other devices. The system calls in this diagram would be at the points where the lines from the processes to the OS meet the upper boundary of the OS rectangle:

 

 

The operation and existence of system services is invisible to users. What evidence or information tells us about them? In case you are a system-call agnostic, witness these interesting and convincing exhibits.

Exhibit A - The Linux Programmer's Guide

"A system call is usually a request to the operating system (kernel) to do a hardware/system-specific or privileged operation. As of Linux-1.2, 140 system calls have been defined [which was as of about 1995]. System calls like close( ) are implemented in the Linux libc. This implementation often involves calling a macro which eventually calls syscall( ). Parameters passed to syscall( ) are the number of the system call followed by the needed arguments. The actual system call numbers can be found in linux/unistd.h.... If new calls appear that don't have a stub in libc yet, you can use syscall( ). As an example, you can close a file using syscall( ) like this (not advised):

#include syscall.h

extern int syscall(int, ...);

int my_close(int filedescriptor)
{
   return syscall(SYS_close, filedescriptor);
} "

Exhibit B - list of system calls

The files /usr/include/asm/unistd.h from the Fedora Core 4 distribution of linux (2005), or syscall_32.tbl from the Fedora 27 distribution (2017), are tantamount to lists of the available services with numbers by which a programmer can call them. So for example if a program wants to open a file, it calls the linux's "open" service, which is number 5. Whereas "The Linux Programmer's Guide" tells us of 1995's 140 calls, the above files reveal about 250 of them as of 2005 and almost 400 in 2017. Here is a quick reference/cheat sheet for linux system calls.

Exhibit C - section 2 of the man pages

Linux uses man pages as a kind of poor man's help system. Genereally there is a page of documentation for each user command. So if you wish to view the documentation for the "cat" command, you would get it by issuing the command "man cat." There are manual pages not only for user commands, but also for a variety of other aspects of the system. In fact, the "man" facility is divided into ten sections and only the first one is devoted to user commands. Section 2 is devoted to system calls. If you wanted to see documentation for the "open" system call, you might try "man open," however you would get the page for the identically named "open" user command. To get the page for the call, it's "man 2 open." Here is the manual page for the open system call. You can get a list of the system calls with the command "man 2 syscalls". Here is the manual page for the syscalls list..

Exhibit D - an assembly language tutorial

Services can be called from within a program directly. However, more commonly there are libraries for common programming language that offer their own parallel set of calls. The program makes the library call, which in turn makes the direct system call. The author of "Introduction to UNIX Assembly Programming" says, "There are two common ways of performing a system call in UNIX OS: trough the C library (libc) wrapper, or directly."

Exhibit E - common C language code

The Bruce Molay textbook Understanding Unix/Linux Programming: A Guide To Theory and Practice offers a number of sample programs to drive home an understanding of these concepts. They are all in C. So they use C library calls to effect system calls. The C library call that programs can use to effect linux's "open," is "fopen." The book's first sample program, more01.c, simulates the operation of the linux "more" command. Note near the top (21st line) there is a call to fopen( ). This is a C program's way of causing a system call.

 

System calls? With all this evidence, no doubt! Must be true; glad you agree.

Other operating systems are structured similarly.