1 .\" Copyright (c) 1980, 1983, 1986, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)intro.2 8.5 (Berkeley) 2/27/95
40 .Nd introduction to system calls and error numbers
42 .Fd #include <errno.h>
44 This section provides an overview of the system calls,
45 their error returns, and other common definitions and concepts.
47 .\".Sy System call restart
51 Nearly all of the system calls provide an error number referenced via
52 the external identifier errno. This identifier is defined in
56 .Dl extern int * __error();
57 .Dl #define errno (* __error())
61 function returns a pointer to a field in the thread specific structure for
62 threads other than the initial thread. For the initial thread and
63 non-threaded processes,
65 returns a pointer to a global
67 variable that is compatible with the previous definition.
69 When a system call detects an error,
70 it returns an integer value
71 indicating failure (usually -1)
75 <This allows interpretation of the failure on receiving
76 a -1 and to take action accordingly.>
77 Successful calls never set
79 once set, it remains until another error occurs.
80 It should only be examined after an error.
81 Note that a number of system calls overload the meanings of these
82 error numbers, and that the meanings must be interpreted according
83 to the type and circumstances of the call.
85 The following is a complete list of the errors and their
89 .It Er 0 Em "Error 0" .
91 .It Er 1 EPERM Em "Operation not permitted" .
92 An attempt was made to perform an operation limited to processes
93 with appropriate privileges or to the owner of a file or other
95 .It Er 2 ENOENT Em "No such file or directory" .
96 A component of a specified pathname did not exist, or the
97 pathname was an empty string.
98 .It Er 3 ESRCH Em "No such process" .
99 No process could be found corresponding to that specified by the given
101 .It Er 4 EINTR Em "Interrupted function call" .
102 An asynchronous signal (such as
106 was caught by the process during the execution of an interruptible
107 function. If the signal handler performs a normal return, the
108 interrupted function call will seem to have returned the error condition.
109 .It Er 5 EIO Em "Input/output error" .
110 Some physical input or output error occurred.
111 This error will not be reported until a subsequent operation on the same file
112 descriptor and may be lost (over written) by any subsequent errors.
113 .It Er 6 ENXIO Em "\&No such device or address" .
114 Input or output on a special file referred to a device that did not
116 made a request beyond the limits of the device.
117 This error may also occur when, for example,
118 a tape drive is not online or no disk pack is
120 .It Er 7 E2BIG Em "Arg list too long" .
121 The number of bytes used for the argument and environment
122 list of the new process exceeded the current limit
126 .Aq Pa sys/param.h ) .
127 .It Er 8 ENOEXEC Em "Exec format error" .
128 A request was made to execute a file
129 that, although it has the appropriate permissions,
130 was not in the format required for an
132 .It Er 9 EBADF Em "Bad file descriptor" .
133 A file descriptor argument was out of range, referred to no open file,
134 or a read (write) request was made to a file that was only open for
137 .It Er 10 ECHILD Em "\&No child processes" .
142 function was executed by a process that had no existing or unwaited-for
144 .It Er 11 EDEADLK Em "Resource deadlock avoided" .
145 An attempt was made to lock a system resource that
146 would have resulted in a deadlock situation.
147 .It Er 12 ENOMEM Em "Cannot allocate memory" .
148 The new process image required more memory than was allowed by the hardware
149 or by system-imposed memory management constraints.
150 A lack of swap space is normally temporary; however,
151 a lack of core is not.
152 Soft limits may be increased to their corresponding hard limits.
153 .It Er 13 EACCES Em "Permission denied" .
154 An attempt was made to access a file in a way forbidden
155 by its file access permissions.
156 .It Er 14 EFAULT Em "Bad address" .
157 The system detected an invalid address in attempting to
158 use an argument of a call.
159 .It Er 15 ENOTBLK Em "Not a block device" .
160 A block device operation was attempted on a non-block device or file.
161 .It Er 16 EBUSY Em "Resource busy" .
162 An attempt to use a system resource which was in use at the time
163 in a manner which would have conflicted with the request.
164 .It Er 17 EEXIST Em "File exists" .
165 An existing file was mentioned in an inappropriate context,
166 for instance, as the new link name in a
169 .It Er 18 EXDEV Em "Improper link" .
170 A hard link to a file on another file system
172 .It Er 19 ENODEV Em "Operation not supported by device" .
173 An attempt was made to apply an inappropriate
174 function to a device,
176 trying to read a write-only device such as a printer.
177 .It Er 20 ENOTDIR Em "Not a directory" .
178 A component of the specified pathname existed, but it was
179 not a directory, when a directory was expected.
180 .It Er 21 EISDIR Em "Is a directory" .
181 An attempt was made to open a directory with write mode specified.
182 .It Er 22 EINVAL Em "Invalid argument" .
183 Some invalid argument was supplied. (For example,
184 specifying an undefined signal to a
189 .It Er 23 ENFILE Em "Too many open files in system" .
190 Maximum number of file descriptors allowable on the system
191 has been reached and a requests for an open cannot be satisfied
192 until at least one has been closed.
193 .It Er 24 EMFILE Em "Too many open files" .
194 <As released, the limit on the number of
195 open files per process is 64.>
197 will obtain the current limit.
198 .It Er 25 ENOTTY Em "Inappropriate ioctl for device" .
199 A control function (see
201 was attempted for a file or
202 special device for which the operation was inappropriate.
203 .It Er 26 ETXTBSY Em "Text file busy" .
204 The new process was a pure procedure (shared text) file
205 which was open for writing by another process, or
206 while the pure procedure file was being executed an
208 call requested write access.
209 .It Er 27 EFBIG Em "File too large" .
210 The size of a file exceeded the maximum (about
211 .if t 2\u\s-231\s+2\d
214 .It Er 28 ENOSPC Em "Device out of space" .
217 to an ordinary file, the creation of a
218 directory or symbolic link, or the creation of a directory
219 entry failed because no more disk blocks were available
220 on the file system, or the allocation of an inode for a newly
221 created file failed because no more inodes were available
223 .It Er 29 ESPIPE Em "Illegal seek" .
226 function was issued on a socket, pipe or
228 .It Er 30 EROFS Em "Read-only file system" .
229 An attempt was made to modify a file or directory
231 on a file system that was read-only at the time.
232 .It Er 31 EMLINK Em "Too many links" .
233 Maximum allowable hard links to a single file has been exceeded (limit
234 of 32767 hard links per file).
235 .It Er 32 EPIPE Em "Broken pipe" .
236 A write on a pipe, socket or
238 for which there is no process
240 .It Er 33 EDOM Em "Numerical argument out of domain" .
241 A numerical input argument was outside the defined domain of the mathematical
243 .It Er 34 ERANGE Em "Numerical result out of range" .
244 A numerical result of the function was too large to fit in the
245 available space (perhaps exceeded precision).
246 .It Er 35 EAGAIN Em "Resource temporarily unavailable" .
247 This is a temporary condition and later calls to the
248 same routine may complete normally.
249 .It Er 36 EINPROGRESS Em "Operation now in progress" .
250 An operation that takes a long time to complete (such as
253 was attempted on a non-blocking object (see
255 .It Er 37 EALREADY Em "Operation already in progress" .
256 An operation was attempted on a non-blocking object that already
257 had an operation in progress.
258 .It Er 38 ENOTSOCK Em "Socket operation on non-socket" .
260 .It Er 39 EDESTADDRREQ Em "Destination address required" .
261 A required address was omitted from an operation on a socket.
262 .It Er 40 EMSGSIZE Em "Message too long" .
263 A message sent on a socket was larger than the internal message buffer
264 or some other network limit.
265 .It Er 41 EPROTOTYPE Em "Protocol wrong type for socket" .
266 A protocol was specified that does not support the semantics of the
267 socket type requested. For example, you cannot use the
273 .It Er 42 ENOPROTOOPT Em "Protocol not available" .
274 A bad option or level was specified in a
279 .It Er 43 EPROTONOSUPPORT Em "Protocol not supported" .
280 The protocol has not been configured into the
281 system or no implementation for it exists.
282 .It Er 44 ESOCKTNOSUPPORT Em "Socket type not supported" .
283 The support for the socket type has not been configured into the
284 system or no implementation for it exists.
285 .It Er 45 EOPNOTSUPP Em "Operation not supported" .
286 The attempted operation is not supported for the type of object referenced.
287 Usually this occurs when a file descriptor refers to a file or socket
288 that cannot support this operation,
289 for example, trying to
291 a connection on a datagram socket.
292 .It Er 46 EPFNOSUPPORT Em "Protocol family not supported" .
293 The protocol family has not been configured into the
294 system or no implementation for it exists.
295 .It Er 47 EAFNOSUPPORT Em "Address family not supported by protocol family" .
296 An address incompatible with the requested protocol was used.
297 For example, you shouldn't necessarily expect to be able to use
302 .It Er 48 EADDRINUSE Em "Address already in use" .
303 Only one usage of each address is normally permitted.
305 .It Er 49 EADDRNOTAVAIL Em "Cannot assign requested address" .
306 Normally results from an attempt to create a socket with an
307 address not on this machine.
308 .It Er 50 ENETDOWN Em "Network is down" .
309 A socket operation encountered a dead network.
310 .It Er 51 ENETUNREACH Em "Network is unreachable" .
311 A socket operation was attempted to an unreachable network.
312 .It Er 52 ENETRESET Em "Network dropped connection on reset" .
313 The host you were connected to crashed and rebooted.
314 .It Er 53 ECONNABORTED Em "Software caused connection abort" .
315 A connection abort was caused internal to your host machine.
316 .It Er 54 ECONNRESET Em "Connection reset by peer" .
317 A connection was forcibly closed by a peer. This normally
318 results from a loss of the connection on the remote socket
319 due to a timeout or a reboot.
320 .It Er 55 ENOBUFS Em "\&No buffer space available" .
321 An operation on a socket or pipe was not performed because
322 the system lacked sufficient buffer space or because a queue was full.
323 .It Er 56 EISCONN Em "Socket is already connected" .
326 request was made on an already connected socket; or,
331 request on a connected socket specified a destination
332 when already connected.
333 .It Er 57 ENOTCONN Em "Socket is not connected" .
334 An request to send or receive data was disallowed because
335 the socket was not connected and (when sending on a datagram socket)
336 no address was supplied.
337 .It Er 58 ESHUTDOWN Em "Cannot send after socket shutdown" .
338 A request to send data was disallowed because the socket
339 had already been shut down with a previous
342 .It Er 60 ETIMEDOUT Em "Operation timed out" .
347 request failed because the connected party did not
348 properly respond after a period of time. (The timeout
349 period is dependent on the communication protocol.)
350 .It Er 61 ECONNREFUSED Em "Connection refused" .
351 No connection could be made because the target machine actively
352 refused it. This usually results from trying to connect
353 to a service that is inactive on the foreign host.
354 .It Er 62 ELOOP Em "Too many levels of symbolic links" .
355 A path name lookup involved more than 32
358 .It Er 63 ENAMETOOLONG Em "File name too long" .
359 A component of a path name exceeded 255
361 characters, or an entire
362 path name exceeded 1023
363 .Pq Dv MAXPATHLEN Ns -1
365 .It Er 64 EHOSTDOWN Em "Host is down" .
366 A socket operation failed because the destination host was down.
367 .It Er 65 EHOSTUNREACH Em "No route to host" .
368 A socket operation was attempted to an unreachable host.
369 .It Er 66 ENOTEMPTY Em "Directory not empty" .
370 A directory with entries other than
374 was supplied to a remove directory or rename call.
375 .It Er 67 EPROCLIM Em "Too many processes" .
376 .It Er 68 EUSERS Em "Too many users" .
377 The quota system ran out of table entries.
378 .It Er 69 EDQUOT Em "Disc quota exceeded" .
381 to an ordinary file, the creation of a
382 directory or symbolic link, or the creation of a directory
383 entry failed because the user's quota of disk blocks was
384 exhausted, or the allocation of an inode for a newly
385 created file failed because the user's quota of inodes
388 .It Er 70 ESTALE Em "Stale NFS file handle" .
389 An attempt was made to access an open file (on an
392 which is now unavailable as referenced by the file descriptor.
393 This may indicate the file was deleted on the
396 other catastrophic event occurred.
397 .It Er 72 EBADRPC Em "RPC struct is bad" .
400 information was unsuccessful.
401 .It Er 73 ERPCMISMATCH Em "RPC version wrong" .
404 on the remote peer is not compatible with
406 .It Er 74 EPROGUNAVAIL Em "RPC prog. not avail" .
407 The requested program is not registered on the remote host.
408 .It Er 75 EPROGMISMATCH Em "Program version wrong" .
409 The requested version of the program is not available
412 .It Er 76 EPROCUNAVAIL Em "Bad procedure for program" .
415 call was attempted for a procedure which doesn't exist
416 in the remote program.
417 .It Er 77 ENOLCK Em "No locks available" .
418 A system-imposed limit on the number of simultaneous file
420 .It Er 78 ENOSYS Em "Function not implemented" .
421 Attempted a system call that is not available on this
423 .It Er 79 EFTYPE Em "Inappropriate file type or format" .
424 The file was the wrong type for the operation, or a data file had
426 .It Er 80 EAUTH Em "Authentication error" .
427 Attempted to use an invalid authentication ticket to mount a
430 .It Er 81 ENEEDAUTH Em "Need authenticator" .
431 An authentication ticket must be obtained before the given
433 filesystem may be mounted.
434 .It Er 82 EIDRM Em "Identifier removed" .
435 An IPC identifier was removed while the current process was waiting on it.
436 .It Er 83 ENOMSG Em "No message of desired type" .
437 An IPC message queue does not contain a message of the desired type, or a
438 message catalog does not contain the requested message.
439 .It Er 84 EOVERFLOW Em "Value too large to be stored in data type" .
440 A numerical result of the function was too large to be stored in the caller
442 .It Er 85 ECANCELED Em "Operation canceled" .
443 The scheduled operation was canceled.
444 .It Er 86 EILSEQ Em "Illegal byte sequence" .
445 While decoding a multibyte character the function came along an
446 invalid or an incomplete sequence of bytes or the given wide
447 character is invalid.
451 Each active process in the system is uniquely identified by a non-negative
452 integer called a process ID. The range of this ID is from 0 to 99999.
453 .It Parent process ID
454 A new process is created by a currently active process; (see
456 The parent process ID of a process is initially the process ID of its creator.
457 If the creating process exits,
458 the parent process ID of each child is set to the ID of a system process,
461 Each active process is a member of a process group that is identified by
462 a non-negative integer called the process group ID. This is the process
463 ID of the group leader. This grouping permits the signaling of related
466 and the job control mechanisms of
469 A session is a set of one or more process groups.
470 A session is created by a successful call to
472 which causes the caller to become the only member of the only process
473 group in the new session.
475 A process that has created a new session by a successful call to
477 is known as a session leader.
478 Only a session leader may acquire a terminal as its controlling terminal (see
480 .It Controlling process
481 A session leader with a controlling terminal is a controlling process.
482 .It Controlling terminal
483 A terminal that is associated with a session is known as the controlling
484 terminal for that session and its members.
486 .It "Terminal Process Group ID"
487 A terminal may be acquired by a session leader as its controlling terminal.
488 Once a terminal is associated with a session, any of the process groups
489 within the session may be placed into the foreground by setting
490 the terminal process group ID to the ID of the process group.
491 This facility is used
492 to arbitrate between multiple jobs contending for the same terminal;
497 .It "Orphaned Process Group"
498 A process group is considered to be
500 if it is not under the control of a job control shell.
501 More precisely, a process group is orphaned
502 when none of its members has a parent process that is in the same session
504 but is in a different process group.
505 Note that when a process exits, the parent process for its children
508 which is in a separate session.
509 Not all members of an orphaned process group are necessarily orphaned
510 processes (those whose creating process has exited).
511 The process group of a session leader is orphaned by definition.
512 .It "Real User ID and Real Group ID"
513 Each user on the system is identified by a positive integer
514 termed the real user ID.
516 Each user is also a member of one or more groups.
517 One of these groups is distinguished from others and
518 used in implementing accounting facilities. The positive
519 integer corresponding to this distinguished group is termed
522 All processes have a real user ID and real group ID.
523 These are initialized from the equivalent attributes
524 of the process that created it.
525 .It "Effective User Id, Effective Group Id, and Group Access List"
526 Access to system resources is governed by two values:
527 the effective user ID, and the group access list.
528 The first member of the group access list is also known as the
530 (In POSIX.1, the group access list is known as the set of supplementary
531 group IDs, and it is unspecified whether the effective group ID is
532 a member of the list.)
534 The effective user ID and effective group ID are initially the
535 process's real user ID and real group ID respectively. Either
536 may be modified through execution of a set-user-ID or set-group-ID
537 file (possibly by one its ancestors) (see
539 By convention, the effective group ID (the first member of the group access
540 list) is duplicated, so that the execution of a set-group-ID program
541 does not result in the loss of the original (real) group ID.
543 The group access list is a set of group IDs
544 used only in determining resource accessibility. Access checks
545 are performed as described below in ``File Access Permissions''.
546 .It "Saved Set User ID and Saved Set Group ID"
547 When a process executes a new file, the effective user ID is set
548 to the owner of the file if the file is set-user-ID, and the effective
549 group ID (first element of the group access list) is set to the group
550 of the file if the file is set-group-ID.
551 The effective user ID of the process is then recorded as the saved set-user-ID,
552 and the effective group ID of the process is recorded as the saved set-group-ID.
553 These values may be used to regain those values as the effective user
554 or group ID after reverting to the real ID (see
556 (In POSIX.1, the saved set-user-ID and saved set-group-ID are optional,
557 and are used in setuid and setgid, but this does not work as desired
560 A process is recognized as a
562 process and is granted special privileges if its effective user ID is 0.
564 .It Special Processes
565 The processes with process IDs of 0, 1, and 2 are special.
566 Process 0 is the scheduler. Process 1 is the initialization process
568 and is the ancestor of every other process in the system.
569 It is used to control the process structure.
570 Process 2 is the paging daemon.
572 An integer assigned by the system when a file is referenced
577 or when a socket is created by
582 which uniquely identifies an access path to that file or socket from
583 a given process or any of its children.
585 Names consisting of up to 255
587 characters may be used to name
588 an ordinary file, special file, or directory.
590 These characters may be selected from the set of all
593 excluding 0 (NUL) and the
599 Note that it is generally unwise to use
606 file names because of the special meaning attached to these characters
610 .Tn NUL Ns -terminated
611 character string starting with an
614 followed by zero or more directory names separated
615 by slashes, optionally followed by a file name.
616 The total length of a path name must be less than 1024
620 If a path name begins with a slash, the path search begins at the
623 Otherwise, the search begins from the current working directory.
624 A slash by itself names the root directory. An empty
625 pathname refers to the current directory.
627 A directory is a special type of file that contains entries
628 that are references to other files.
629 Directory entries are called links. By convention, a directory
630 contains at least two links,
638 respectively. Dot refers to the directory itself and
639 dot-dot refers to its parent directory.
640 .It "Root Directory and Current Working Directory"
641 Each process has associated with it a concept of a root directory
642 and a current working directory for the purpose of resolving path
643 name searches. A process's root directory need not be the root
644 directory of the root file system.
645 .It File Access Permissions
646 Every file in the file system has a set of access permissions.
647 These permissions are used in determining whether a process
648 may perform a requested operation on the file (such as opening
649 a file for writing). Access permissions are established at the
650 time a file is created. They may be changed at some later time
655 File access is broken down according to whether a file may be: read,
656 written, or executed. Directory files use the execute
657 permission to control if the directory may be searched.
659 File access permissions are interpreted by the system as
660 they apply to three different classes of users: the owner
661 of the file, those users in the file's group, anyone else.
662 Every file has an independent set of access permissions for
663 each of these classes. When an access check is made, the system
664 decides if permission should be granted by checking the access
665 information applicable to the caller.
667 Read, write, and execute/search permissions on
668 a file are granted to a process if:
670 The process's effective user ID is that of the super-user. (Note:
671 even the super-user cannot execute a non-executable file.)
673 The process's effective user ID matches the user ID of the owner
674 of the file and the owner permissions allow the access.
676 The process's effective user ID does not match the user ID of the
677 owner of the file, and either the process's effective
678 group ID matches the group ID
679 of the file, or the group ID of the file is in
680 the process's group access list,
681 and the group permissions allow the access.
683 Neither the effective user ID nor effective group ID
684 and group access list of the process
685 match the corresponding user ID and group ID of the file,
686 but the permissions for ``other users'' allow access.
688 Otherwise, permission is denied.
689 .It Sockets and Address Families
691 A socket is an endpoint for communication between processes.
692 Each socket has queues for sending and receiving data.
694 Sockets are typed according to their communications properties.
695 These properties include whether messages sent and received
696 at a socket require the name of the partner, whether communication
697 is reliable, the format used in naming message recipients, etc.
699 Each instance of the system supports some
700 collection of socket types; consult
702 for more information about the types available and
705 Each instance of the system supports some number of sets of
706 communications protocols. Each protocol set supports addresses
707 of a certain format. An Address Family is the set of addresses
708 for a specific group of protocols. Each socket has an address
709 chosen from the address family in which the socket was created.