intro(2) intro(2)
NAME
intro - introduction to system calls and error numbers
SYNOPSIS
#include <errno.h>
DESCRIPTION
This section describes all of the system calls. Most of
these calls have one or more error returns. An error
condition is indicated by an otherwise impossible returned
value. This is almost always -1; the individual
descriptions specify the details. An error number is also
made available in the external variable errno. errno is not
cleared on successful calls, so it should be tested only
after an error has been indicated.
There is a table of messages associated with each error, and
a routine for printing the message; see perror(3C). Each
system call description attempts to list all possible error
numbers. The following is a complete list of the error
numbers and their names as defined in <errno.h>.
1 EPERM Not super-user
Typically this error indicates an attempt to modify a
file in some way forbidden except to its owner or
super-user. It is also returned for attempts by
ordinary users to do things allowed only to the super-
user.
2 ENOENT No such file or directory
This error occurs when a file name is specified and the
file should exist but doesn't, or when one of the
directories in a path name does not exist.
3 ESRCH No such process
No process can be found corresponding to that specified
by pid in kill or ptrace.
4 EINTR Interrupted system call
An asynchronous signal (such as interrupt or quit),
which the user has elected to catch, occurred during a
system call. If execution is resumed after processing
the signal, it will appear as if the interrupted system
call returned this error condition.
5 EIO I/O error
Some physical I/O error has occurred. This error may
in some cases occur on a call following the one to
which it actually applies.
6 ENXIO No such device or address
I/O on a special file refers to a subdevice which does
Page 1 (last mod. 1/14/87)
intro(2) intro(2)
not exist, or beyond the limits of the device. It may
also occur when, for example, a tape drive is not on-
line or no disk pack is loaded on a drive.
7 E2BIG Arg list too long
An argument list longer than 5,120 bytes is presented
to a member of the exec family.
8 ENOEXEC Exec format error
A request is made to execute a file which, although it
has the appropriate permissions, does not start with a
valid magic number (see a.out(4)).
9 EBADF Bad file number
Either a file descriptor refers to no open file, or a
read (respectively, write) request is made to a file
which is open only for writing (respectively, reading).
10 ECHILD No children
A wait was executed by a process that had no existing
or unwaited-for child processes.
11 EAGAIN No more processes
A fork failed because the system's process table is
full or the user is not allowed to create any more
processes.
12 ENOMEM Not enough space
During an exec, brk, or sbrk, a program asks for more
space than the system is able to supply. This is not a
temporary condition; the maximum space size is a system
parameter. The error may also occur if the arrangement
of text, data, and stack segments requires too many
segmentation registers, or if there is not enough swap
space during a fork.
13 EACCES Permission denied
An attempt was made to access a file in a way forbidden
by the protection system.
14 EFAULT Bad address
The system encountered a hardware fault in attempting
to use an argument of a system call.
15 ENOTBLK Block device required
A non-block file was mentioned where a block device was
required, e.g., in mount.
16 EBUSY Mount device busy
An attempt was made to mount a device that was already
mounted or an attempt was made to dismount a device on
which there is an active file (open file, current
Page 2 (last mod. 1/14/87)
intro(2) intro(2)
directory, mounted-on file, active text segment). It
will also occur if an attempt is made to enable
accounting when it is already enabled. The device or
resource is currently unavailable.
17 EEXIST File exists
An existing file was mentioned in an inappropriate
context, e.g., link.
18 EXDEV Cross-device link
A link to a file on another device was attempted.
19 ENODEV No such device
An attempt was made to apply an inappropriate system
call to a device; e.g., read a write-only device.
20 ENOTDIR Not a directory
A non-directory was specified where a directory is
required, for example in a path prefix or as an
argument to chdir(2).
21 EISDIR Is a directory
An attempt was made to write on a directory.
22 EINVAL Invalid argument
Some invalid argument (e.g., dismounting a non-mounted
device; mentioning an undefined signal in signal, or
kill; reading or writing a file for which lseek has
generated a negative pointer). Also set by the math
functions described in the (3M) entries of this manual.
23 ENFILE File table overflow
The system file table is full, and temporarily no more
opens can be accepted.
24 EMFILE Too many open files
No process may have more than 20 file descriptors open
at a time. When a record lock is being created with
fcntl, there are too many files with record locks on
them.
25 ENOTTY Not a typewriter
An attempt was made to ioctl(2) a file that is not a
special character device. The file mentioned in stty
or gtty is not a terminal or one of the other devices
to which these calls apply.
26 ETXTBSY Text file busy
An attempt was made to execute a pure-procedure program
which is currently open for writing. Also an attempt
to open for writing a pure-procedure program that is
being executed.
Page 3 (last mod. 1/14/87)
intro(2) intro(2)
Note: If you are running an NFS system and you are
accessing a shared binary remotely, it is possible that
you will not get this errno.
27 EFBIG File too large
The size of a file exceeded the maximum file size
(1,082,201,088 bytes) or ULIMIT; see ulimit(2).
28 ENOSPC No space left on device
During a write to an ordinary file, there is no free
space left on the device. In fcntl, the setting or
removing of record locks on a file cannot be
accomplished because there are no more record entries
left on the system
29 ESPIPE Illegal seek
An lseek was issued to a pipe. This error should also
be issued for other non-seekable devices.
30 EROFS Read-only file system
An attempt to modify a file or directory was made on a
device mounted read-only.
31 EMLINK Too many links
An attempt to make more than the maximum number of
links (1000) to a file.
32 EPIPE Broken pipe
A write on a pipe for which there is no process to read
the data. This condition normally generates a signal;
the error is returned if the signal is ignored.
33 EDOM Argument out of domain of func
The argument of a function in the math package (3M) is
out of the domain of the function.
34 ERANGE Math result not representable
The value of a function in the math package (3M) is not
representable within machine precision.
35 ENOMSG No message of desired type
An attempt was made to receive a message of a type that
does not exist on the specified message queue; see
msgop(2).
36 EIDRM Identifier Removed
This error is returned to processes that resume
execution due to the removal of an identifier from the
file system's name space (see msgctl(2), semctl(2), and
shmctl(2)).
37 ECHRNG Channel number out of range
Page 4 (last mod. 1/14/87)
intro(2) intro(2)
38 EL2NSYNC Level 2 not synchronized
39 EL3HLT Level 3 halted
40 EL3RST Level 3 reset
41 ELNRNG Link number out of range
42 EUNATCH Protocol driver not attached
43 ENOCSI No CSI structure available
44 EL2HLT Level 2 halted
45 EDEADLK Deadlock
A deadlock situation was detected and avoided.
55 EWOULDBLOCK Operation would block
An operation which would cause a process to block was
attempted on an object in non-blocking mode (see
socket(2N)).
56 EINPROGRESS Operation now in progress
An operation which takes a long time to complete (such
as a connect(2N)) was started on a non-blocking object
(see socket(2N)).
57 EALREADY Operation already in progress
An operation was attempted on a non-blocking object
which already had an operation in progress.
58 ENOTSOCK Socket operation on non-socket
59 EDESTADDRREQ Destination address required
A required address was omitted from an operation on a
socket.
60 EMSGSIZE Message too long
A message sent on a socket was larger than the internal
message buffer.
61 EPROTOTYPE Protocol wrong type for socket
A protocol was specified which does not support the
semantics of the socket type requested. For example,
you cannot use the internet UDP protocol with type
SOCKSTREAM.
62 ENOPROTOOPT Protocol not available
In this incarnation of the system.
63 EPROTONOSUPPORT Protocol not supported
In this incarnation of the system.
Page 5 (last mod. 1/14/87)
intro(2) intro(2)
64 ESOCKTNOSUPPORT Socket type not supported
In this incarnation of the system.
65 EOPNOTSUPP Operation not supported on socket
For example, trying to accept a connection on a
datagram socket.
66 EPFNOSUPPORT Protocol family not supported
In this incarnation of the system.
67 EAFNOSUPPORT Address family not supported by protocol
family
An address incompatible with the requested protocol was
used. For example, you shouldn't necessarily expect to
be able to use PUP Internet addresses with ARPA
Internet protocols.
68 EADDRINUSE Address already in use
Only one usage of each address is normally permitted.
69 EADDRNOTAVAIL Can't assign requested address
Normally results from an attempt to create a socket
with an address not on this machine.
70 ENETDOWN Network is down
A socket operation encountered a dead network.
71 ENETUNREACH Network is unreachable
A socket operation was attempted to an unreachable
network.
72 ENETRESET Network dropped connection on reset
The host you were connected to crashed and rebooted.
73 ECONNABORTED Software caused connection abort
A connection abort was caused internal to your host
machine.
74 ECONNRESET Connection reset by peer
75 ENOBUFS No buffer space available
For a socket or a pipe in the buffer pool.
76 EISCONN Socket is already connected
77 ENOTCONN Socket is not connected
78 ESHUTDOWN Can't send after socket shutdown
79 ETOOMANYREFS Too many references: can't splice
80 ETIMEDOUT Connection timed out
Page 6 (last mod. 1/14/87)
intro(2) intro(2)
Due to failure to initiate properly or because keep-
alives failed.
81 ECONNREFUSED Connection refused
No connection could be made because the target machine
actively refused it.
82 ELOOP Too many levels of symbolic links
83 ENAMETOOLONG File name too long
A component of a path name exceeded 14 characters, or
an entire path name exceeded 1023 characters.
84 EHOSTDOWN Host is down
A socket operation encountered a defunct host.
85 EHOSTUNREACH No route to host
A socket operation was attempted to an unreachable
host.
86 ENOTEMPTY Directory not empty
87 ENOSTR Device not a stream
88 ENODATA No data (for no delay I/O)
89 ETIME Timer expired
90 ENOSR Out of stream resources
95 ESTALE Stale NFS file handle
96 EREMOTE Too many levels of remote in path
97 EPROCLIM Too many processes
98 EUSERS Too many users
99 EDQUOT Disc quota exceeded
100 EDEADLOCK Locking deadlock error
Returned by locking(2) system call if deadlock would
occur or when locktable overflows.
DEFINITIONS
Process ID
Each active process in the system is uniquely identified by
a positive integer called a process ID. The range of this
ID is from 1 to 30,000.
Parent Process ID
A new process is created by a currently active process; see
Page 7 (last mod. 1/14/87)
intro(2) intro(2)
fork(2). The parent process ID of a process is the process
ID of its creator.
Process Group ID
Each active process is a member of a process group that is
identified by a positive integer called the process group
ID. This ID is the process ID of the group leader. This
grouping permits the signaling of related processes; see
kill(2).
Tty Group ID
Each active process can be a member of a terminal group that
is identified by a positive integer called the tty group ID.
This grouping is used to terminate a group of related
processes upon termination of one of the processes in the
group; see exit(2) and signal(3).
Real User ID and Real Group ID
Each user allowed on the system is identified by a positive
integer called a real user ID.
Each user is also a member of a group. The group is
identified by a positive integer called the real group ID.
An active process has a real user ID and real group ID that
are set to the real user ID and real group ID, respectively,
of the user responsible for the creation of the process.
Effective User ID and Effective Group ID
An active process has an effective user ID and an effective
group ID that are used to determine file access permissions
(see below). The effective user ID and effective group ID
are equal to the process's real user ID and real group ID
respectively, unless the process or one of its ancestors
evolved from a file that had the set-user-ID bit or set-
group ID bit set; see exec(2).
Super-user
A process is recognized as a ``super-user'' process and is
granted special privileges if its effective user ID is 0.
Special Processes
The processes with a process ID of 0 and a process ID of 1
are special processes and are referred to as proc0 and
proc1.
proc0 is the scheduler. proc1 is the initialization process
(init). proc1 is the ancestor of every other process in the
system and is used to control the process structure.
File Descriptor
A file descriptor is a small integer used to do I/O on a
Page 8 (last mod. 1/14/87)
intro(2) intro(2)
file. The value of a file descriptor is from 0 to 19. A
process may have no more than 20 file descriptors (0-19)
open simultaneously. A file descriptor is returned by
system calls such as open(2), or pipe(2). The file
descriptor is used as an argument by calls such as read(2),
write(3), ioctl(2), and close(2).
File Name.
Names consisting of 1 to 14 characters may be used to name
an ordinary file, special file or directory.
These characters may be selected from the set of all
character values excluding \0 (null) and the ASCII code for
/ (slash).
Note that it is generally unwise to use *, ?, [, or ] as
part of file names because of the special meaning attached
to these characters by the shell. See sh(1). Although
permitted, it is advisable to avoid the use of unprintable
characters in file names.
Path Name and Path Prefix
A path name is a null-terminated character string starting
with an optional slash (/), followed by zero or more
directory names separated by slashes, optionally followed by
a file name.
More precisely, a path name is a null-terminated character
string constructed as follows:
<path-name>::=<file-name>|<path-prefix><file-name>|/
<path-prefix>::=<rtprefix>|/<rtprefix>
<rtprefix>::=<dirname>/|<rtprefix><dirname>/
where <file-name> is a string of 1 to 14 characters other
than the ASCII slash and null, and <dirname> is a string of
1 to 14 characters (other than the ASCII slash and null)
that names a directory.
If a path name begins with a slash, the path search begins
at the root directory. Otherwise, the search begins from
the current working directory.
A slash by itself names the root directory.
Unless specifically stated otherwise, the null path name is
treated as if it named a non-existent file.
Directory
Directory entries are called links. By convention, a
directory contains at least two links, . and .., referred to
as ``dot'' and ``dot-dot'' respectively. Dot refers to the
Page 9 (last mod. 1/14/87)
intro(2) intro(2)
directory itself and dot-dot refers to its parent directory.
Root Directory and Current Working Directory
Each process has associated with it a concept of a root
directory and a current working directory for the purpose of
resolving path name searches. The root directory of a
process need not be the root directory of the root file
system.
File Access Permissions
Read, write, and execute/search permissions on a file are
granted to a process if one or more of the following is
true:
The effective user ID of the process is super-user.
The effective user ID of the process matches the user ID
of the owner of the file and the appropriate access bit
of the ``owner'' portion (0700) of the file mode is set.
The effective user ID of the process does not match the
user ID of the owner of the file, and the effective group
ID of the process matches the group of the file and the
appropriate access bit of the ``group'' portion (070) of
the file mode is set.
The effective user ID of the process does not match the
user ID of the owner of the file, and the effective group
ID of the process does not match the group ID of the
file, and the appropriate access bit of the ``other''
portion (07) of the file mode is set.
Otherwise, the corresponding permissions are denied.
Message Queue Identifier
A message queue identifier (msqid) is a unique positive
integer created by a msgget(2) system call. Each msqid has
a message queue and a data structure associated with it.
The data structure is referred to as msqid ds and contains
the following members:
struct ipc_perm msg_perm; /* operation permission struct*/
ushort msg_qnum; /* number of msgs on q*/
ushort msg_qbytes; /* max number of bytes on q*/
ushort msg_lspid; /* pid of last msgsnd operation*/
ushort msg_lrpid; /* pid of last msgrcv operation*/
time_t msg_stime; /* last msgsnd time*/
time_t msg_rtime; /* last msgrcv time*/
time_t msg_ctime; /* last change time*/
/* Times measured in secs since*/
/* 00:00:00 GMT, Jan. 1, 1970*/
Page 10 (last mod. 1/14/87)
intro(2) intro(2)
msgperm is an ipcperm structure that specifies the message
operation permission (see below). This structure includes
the following members:
ushort cuid; /* creator user id */
ushort cgid; /* creator group id */
ushort uid; /* user id */
ushort gid; /* group id */
ushort mode; /* r/w permission */
msgqnum is the number of messages currently on the queue.
msgqbytes is the maximum number of bytes allowed on the
queue. msglspid is the process id of the last process that
performed a msgsnd operation. msglrpid is the process id
of the last process that performed a msgrcv operation.
msgstime is the time of the last msgsnd operation,
msgrtime is the time of the last msgrcv operation, and
msgctime is the time of the last msgctl(2) operation that
changed a member of the above structure.
Message Operation Permissions
In the msgop(2) and msgctl(2) system call descriptions, the
permission required for an operation is given as "{token}",
where "token" is the type of permission needed interpreted
as follows:
00400 Read by user
00200 Write by user
00060 Read, Write by group
00006 Read, Write by others
Read and Write permissions on a msqid are granted to a
process if one or more of the following is true:
The effective user ID of the process is super-user.
The effective user ID of the process matches
msgperm.[c]uid in the data structure associated with
msqid and the appropriate bit of the ``user'' portion
(0600) of msgperm.mode is set.
The effective user ID of the process does not match
msgperm.[c]uid and the process's effective group ID
matches msgperm.[c]gid and the appropriate bit of the
``group'' portion (060) of msgperm.mode is set.
The effective user ID of the process does not match
msgperm.[c]uid and the effective group ID of the process
does not match msgperm.[c]gid and the appropriate bit of
the ``other'' portion (06) of msgperm.mode is set.
Otherwise, the corresponding permissions are denied.
Page 11 (last mod. 1/14/87)
intro(2) intro(2)
Semaphore Identifier
A semaphore identifier (semid) is a unique positive integer
created by a semget(2) system call. Each semid has a set of
semaphores and a data structure associated with it. The
data structure is referred to as semid ds and contains the
following members:
struct ipc_perm sem_perm; /* operation permission struct */
ushort sem_nsems; /* number of sems in set */
time_t sem_otime; /* last operation time */
time_t sem_ctime; /* last change time */
/* Times measured in secs since */
/* 00:00:00 GMT, Jan. 1, 1970 */
semperm is an ipcperm structure that specifies the
semaphore operation permission (see below). This structure
includes the following members:
ushort cuid; /* creator user id */
ushort cgid; /* creator group id */
ushort uid; /* user id */
ushort gid; /* group id */
ushort mode; /* r/a permission */
The value of semnsems is equal to the number of semaphores
in the set. Each semaphore in the set is referenced by a
positive integer referred to as a semnum. Sem_num values
run sequentially from 0 to the value of sem_nsems minus 1.
semotime is the time of the last semop(2) operation, and
semctime is the time of the last semctl(2) operation that
changed a member of the above structure.
A semaphore is a data structure that contains the following
members:
ushort semval; /* semaphore value */
short sempid; /* pid of last operation */
ushort semncnt; /* # awaiting semval > cval */
ushort semzcnt; /* # awaiting semval = 0 */
semval is a non-negative integer. sempid is equal to the
process ID of the last process that performed a semaphore
operation on this semaphore. semncnt is a count of the
number of processes that are currently suspended awaiting
this semaphore's semval to become greater than its current
value. semzcnt is a count of the number of processes that
are currently suspended awaiting this semaphore's semval to
become zero.
Semaphore Operation Permissions
In the semop(2) and semctl(2) system call descriptions, the
permission required for an operation is given as "{token}",
Page 12 (last mod. 1/14/87)
intro(2) intro(2)
where "token" is the type of permission needed interpreted
as follows:
00400 Read by user
00200 Alter by user
00060 Read, Alter by group
00006 Read, Alter by others
Read and Alter permissions on a semid are granted to a
process if one or more of the following is true:
The effective user ID of the process is super-user.
The effective user ID of the process matches
semperm.[c]uid in the data structure associated with
semid and the appropriate bit of the ``user'' portion
(0600) of semperm.mode is set.
The effective user ID of the process does not match
semperm.[c]uid and the effective group ID of the process
matches semperm.[c]gid and the appropriate bit of the
``group'' portion (060) of semperm.mode is set.
The effective user ID of the process does not match
semperm.[c]uid and the effective group ID of the process
does not match semperm.[c]gid and the appropriate bit of
the ``other'' portion (06) of semperm.mode is set.
Otherwise, the corresponding permissions are denied.
Shared Memory Identifier
A shared memory identifier (shmid) is a unique positive
integer created by a shmget(2) system call. Each shmid has
a segment of memory (referred to as a shared memory segment)
and a data structure associated with it. The data structure
is referred to as shmidds and contains the following
members:
struct ipc_perm shm_perm; /* operation permission struct*/
int shm_segsz; /* size of segment*/
ushort shm_cpid; /* creator pid*/
ushort shm_lpid; /* pid of last operation*/
short shm_nattch; /* number of current attaches*/
time_t shm_atime; /* last attach time*/
time_t shm_dtime; /* last detach time*/
time_t shm_ctime; /* last change time*/
/* Times measured in secs since*/
/* 00:00:00 GMT, Jan. 1, 1970*/
shmperm is an ipcperm structure that specifies the shared
memory operation permission (see below). This structure
includes the following members:
Page 13 (last mod. 1/14/87)
intro(2) intro(2)
ushort cuid; /* creator user id */
ushort cgid; /* creator group id */
ushort uid; /* user id */
ushort gid; /* group id */
ushort mode; /* r/w permission */
shmsegsz specifies the size of the shared memory segment.
shmcpid is the process ID of the process that created the
shared memory identifier. shmlpid is the process ID of the
last process that performed a shmop(2) operation.
shmnattch is the number of processes that currently have
this segment attached. shmatime is the time of the last
shmat operation, shmdtime is the time of the last shmdt
operation, and shmctime is the time of the last shmctl(2)
operation that changed one of the members of the above
structure.
Shared Memory Operation Permissions
In the shmop(2) and shmctl(2) system call descriptions, the
permission required for an operation is given as "{token}",
where "token" is the type of permission needed interpreted
as follows:
00400 Read by user
00200 Write by user
00060 Read, Write by group
00006 Read, Write by others
Read and Write permissions on a shmid are granted to a
process if one or more of the following is true:
The effective user ID of the process is super-user.
The effective user ID of the process matches
shmperm.[c]uid in the data structure associated with
shmid and the appropriate bit of the ``user'' portion
(0600) of shmperm.mode is set.
The effective user ID of the process does not match
shmperm.[c]uid and the effective group ID of the process
matches shmperm.[c]gid and the appropriate bit of the
``group'' portion (060) of shmperm.mode is set.
The effective user ID of the process does not match
shmperm.[c]uid and the effective group ID of the process
does not match shmperm.[c]gid and the appropriate bit of
the ``other'' portion (06) of shmperm.mode is set.
Otherwise, the corresponding permissions are denied.
SEE ALSO
close(2), ioctl(2), open(2), pipe(2), read(2), write(2),
Page 14 (last mod. 1/14/87)
intro(2) intro(2)
intro(3).
Page 15 (last mod. 1/14/87)