Status Values Returned from System Calls
To provide a consistent interface between application processes and the
operating system kernel, a minimal return-value interface is supported by a
language's run-time library.
The kernel will use a consistent mechanism, such as using a processor
register or the top of the run-time stack, to return a status indicator to a
process. As this mechanism is usually of a fixed size, such as 32 bits,
the value returned is nearly always an integer,
occasionally a pointer (an integral value interpreted as a memory address).
For this reason, globally accessible values such as errno,
convey additional state,
and values 'returned' via larger structures are passed to the kernel
by reference (cf. getrusage() - discussed later).
The status interface employed by Unix/Linux and its C interface involves the
globally accessible integer variable errno.
From /usr/include/sys/errno.h:
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
|
(Most) system calls consistently return an integer value:
- with a value of zero on success, or
- with a non-zero value on failure,
and further description of the error is provided by errno.
Obvious exceptions are those system calls needing to return many possible
correct values - such as open() and read().
Here we often see -1 as the return value indicating failure.
CITS2002 Systems Programming, Lecture 10, p3, 22nd August 2023.
|