Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 13: System Calls


The situation is more interesting ifreadis interrupted by theSIGINTsignal and BSD behavior is activated
by means ofSA_RESTART, as in the sample program. In this case, the signal handler is invoked,signaled
is set to 1, and a message is output to indicate thatSIGINTwas received — but the program is not ter-
minated. Why? After running the handler, the BSD mechanism restarts thereadcall and again waits for
entry of a character. The!signaledcondition of thewhileloop does not apply and is not evaluated. The
program can therefore no longer be terminated by sending theSIGNITsignal, although the code suggests
that this is so.

13.2 Available System Calls


Before going into the technical details of system call implementation by the kernel (and by the userspace
library), it is useful to take a brief look at the actual functions made available by the kernel in the form of
system calls.

Each system call is identified by means of a symbolic constant whose platform-dependentdefinition is
specified in<asm-arch/unistd.h>. Since not all system calls are supported on all architectures (some
combinations are meaningless), the number of available calls varies from platform to platform — roughly
speaking, there are always upward of 200 calls. As a result of changes to the kernel implementation of
system calls over time, some calls are now superfluous, and their numbers are no longer used — the
SPARC port (on 32-bit processors) boasts a large number of extinct calls that give rise to ‘‘gaps‘‘ in the
list of calls.

It is simpler for programmers to group system calls into functional categories as they are not interested
in their individual numbers — they are concerned only with the symbolic names and the meaning of the
calls. The followingshortlist — which makes no claim to be complete — gives an overview of the various
categories and their most important system calls.

Process ManagementProcesses are at the center of the system, so it’s not surprising that a large number
of system calls are devoted to process management. The functions provided by the calls range from
querying simple information to starting new processes:
❑ forkandvforksplit an existing process into two new processes as described in Chapter 2.
cloneis an enhanced version offorkthat supports, among other things, the generation of
threads.
❑ exitends a process and frees its resources.
❑ A whole host of system calls exist to query (and set) process properties such as
PID, UID, and so on.; most of these calls simply read or modify a field in the task
structure. The following can be read: PID, GID, PPID, SID, UID, EUID, PGID, EGID,
and PGRP. The following can be set: UID, GID, REUID, REGID, SID, SUID, and
FSGID.
System calls are named in accordance with a logical scheme that uses designations such as
setgid,setuid,andgeteuid.
❑ personalitydefines the execution environment of an application and is used, for
instance, in the implementation of binary emulations.
❑ ptraceenables system call tracing and is the platform on which the abovestracetool
builds.
Free download pdf