symlink

title: symlink(7)

summary: symbolic link handling

text:
# symlink(7)

## NAME
symlink - symbolic link handling

## DESCRIPTION
Symbolic links are files that act as pointers to other files. To understand their behavior, you must first understand how hard links work.

A hard link to a file is indistinguishable from the original file because it is a reference to the object underlying the original filename. (To be precise: each of the hard links to a file is a reference to the same inode number, where an inode number is an index into the inode table, which contains metadata about all files on a filesystem. See stat(2).) Changes to a file are independent of the name used to reference the file. Hard links may not refer to directories (to prevent the possibility of loops within the filesystem tree, which would confuse many programs) and may not refer to files on different filesystems (because inode numbers are not unique across filesystems).

A symbolic link is a special type of file whose contents are a string that is the pathname of another file, the file to which the link refers. (The contents of a symbolic link can be read using readlink(2).) In other words, a symbolic link is a pointer to another name, and not to an underlying object. For this reason, symbolic links may refer to directories and may cross filesystem boundaries.

There is no requirement that the pathname referred to by a symbolic link should exist. A symbolic link that refers to a pathname that does not exist is said to be a dangling link.

Because a symbolic link and its referenced object coexist in the filesystem name space, confusion can arise in distinguishing between the link itself and the referenced object. On historical systems, commands and system calls adopted their own link-following conventions in a somewhat ad-hoc fashion. Rules for a more uniform approach, as they are implemented on Linux and other systems, are outlined here. It is important that site-local applications also conform to these rules, so that the user interface can be as consistent as possible.

### Magic links
There is a special class of symbolic-link-like objects known as "magic links", which can be found in certain pseudofilesystems such as proc(5) (examples include /proc/[pid]/exe and /proc/[pid]/fd/*). Unlike normal symbolic links, magic links are not resolved through pathname-expansion, but instead act as direct references to the kernel's own representation of a file handle. As such, these magic links allow users to access files which cannot be referenced with normal paths (such as unlinked files still referenced by a running program ).

Because they can bypass ordinary mount_namespaces(7)-based restrictions, magic links have been used as attack vectors in various exploits.

### Symbolic link ownership, permissions, and timestamps
The owner and group of an existing symbolic link can be changed using lchown(2). The only time that the ownership of a symbolic link matters is when the link is being removed or renamed in a directory that has the sticky bit set (see stat(2)).

The last access and last modification timestamps of a symbolic link can be changed using utimensat(2) or lutimes(3).

On Linux, the permissions of an ordinary symbolic link are not used in any operations; the permissions are always 0777 (read, write, and execute for all user categories), and can't be changed.

However, magic links do not follow this rule. They can have a non-0777 mode, though this mode is not currently used in any permission checks.

### Obtaining a file descriptor that refers to a symbolic link
Using the combination of the O_PATH and O_NOFOLLOW flags to open(2) yields a file descriptor that can be passed as the dirfd argument in system calls such as fstatat(2), fchownat(2), fchmodat(2), linkat(2), and readlinkat(2), in order to operate on the symbolic link itself (rather than the file to which it refers).

By default (i.e., if the AT_SYMLINK_FOLLOW flag is not specified), if name_to_handle_at(2) is applied to a symbolic link, it yields a handle for the symbolic link (rather than the file to which it refers). One can then obtain a file descriptor for the symbolic link (rather than the file to which it refers) by specifying the O_PATH flag in a subsequent call to open_by_handle_at(2). Again, that file descriptor can be used in the aforementioned system calls to operate on the symbolic link itself.

### Handling of symbolic links by system calls and commands
Symbolic links are handled either by operating on the link itself, or by operating on the object referred to by the link. In the latter case, an application or system call is said to follow the link. Symbolic links may refer to other symbolic links, in which case the links are dereferenced until an object that is not a symbolic link is found, a symbolic link that refers to a file which does not exist is found, or a loop is detected. (Loop detection is done by placing an upper limit on the number of links that may be followed, and an error results if this limit is exceeded.)

There are three separate areas that need to be discussed. They are as follows:

1.

Symbolic links used as filename arguments for system calls.

2.

Symbolic links specified as command-line arguments to utilities that are not traversing a file tree.

3.

Symbolic links encountered by utilities that are traversing a file tree (either specified on the command line or encountered as part of the file hierarchy walk).

Before describing the treatment of symbolic links by system calls and commands, we require some terminology. Given a pathname of the form a/b/c, the part preceding the final slash (i.e., a/b) is called the dirname component, and the part following the final slash (i.e., c) is called the basename component.

### Treatment of symbolic links in system calls
The first area is symbolic links used as filename arguments for system calls.

The treatment of symbolic links within a pathname passed to a system call is as follows:

1.

Within the dirname component of a pathname, symbolic links are always followed in nearly every system call. (This is also true for commands.) The one exception is openat2(2), which provides flags that can be used to explicitly prevent following of symbolic links in the dirname component.

2.

Except as noted below, all system calls follow symbolic links in the basename component of a pathname. For example, if there were a symbolic link slink which pointed to a file named afile, the system call open("slink" ...) would return a file descriptor referring to the file afile.

Various system calls do not follow links in the basename component of a pathname, and operate on the symbolic link itself. They are: lchown(2), lgetxattr(2), llistxattr(2), lremovexattr(2), lsetxattr(2), lstat(2), readlink(2), rename(2), rmdir(2), and unlink(2).

Certain other system calls optionally follow symbolic links in the basename component of a pathname. They are: faccessat(2), fchownat(2), fstatat(2), linkat(2), name_to_handle_at(2), open(2), openat(2), open_by_handle_at(2), and utimensat(2); see their manual pages for details. Because remove(3) is an alias for unlink(2), that library function also does not follow symbolic links. When rmdir(2) is applied to a symbolic link, it fails with the error ENOTDIR.

link(2) warrants special discussion. POSIX.1-2001 specifies that link(2) should dereference oldpath if it is a symbolic link. However, Linux does not do this. (By default, Solaris is the same, but the POSIX.1-2001 specified behavior can be obtained with suitable compiler options.) POSIX.1-2008 changed the specification to allow either behavior in an implementation.

### Commands not traversing a file tree
The second area is symbolic links, specified as command-line filename arguments, to commands which are not traversing a file tree.

Except as noted below, commands follow symbolic links named as command-line arguments. For example, if there were a symbolic link slink which pointed to a file named afile, the command cat slink would display the contents of the file afile.

It is important to realize that this rule includes commands which may optionally traverse file trees; for example, the command chown file is included in this rule, while the command chown -R file, which performs a tree traversal, is not. (The latter is described in the third area, below.)

If it is explicitly intended that the command operate on the symbolic link instead of following the symbolic link—for example, it is desired that chown slink change the ownership of the file that slink is, whether it is a symbolic link or not—then the -h option should be used. In the above example, chown root slink would change the ownership of the file referred to by slink, while chown -h root slink would change the ownership of slink itself.

There are some exceptions to this rule:

- The mv(1) and rm(1) commands do not follow symbolic links named as arguments, but respectively attempt to rename and delete them. (Note, if the symbolic link references a file via a relative path, moving it to another directory may very well cause it to stop working, since the path may no longer be correct.)

- The ls(1) command is also an exception to this rule. For compatibility with historic systems (when ls(1) is not doing a tree walk—that is, -R option is not specified), the ls(1) command follows symbolic links named as arguments if the -H or -L option is specified, or if the -F, -d, or -l options are not specified. (The ls(1) command is the only command where the -H and -L options affect its behavior even though it is not doing a walk of a file tree.)

- The file(1) command is also an exception to this rule. The file(1) command does not follow symbolic links named as argument by default. The file(1) command does follow symbolic links named as argument if the -L option is specified.

### Commands traversing a file tree
The following commands either optionally or always traverse file trees: chgrp(1), chmod(1), chown(1), cp(1), du(1), find(1), ls(1), pax(1), rm(1), and tar(1).

It is important to realize that the following rules apply equally to symbolic links encountered during the file tree traversal and symbolic links listed as command-line arguments.

The first rule applies to symbolic links that reference files other than directories. Operations that apply to symbolic links are performed on the links themselves, but otherwise the links are ignored.

The command rm -r slink directory will remove slink, as well as any symbolic links encountered in the tree traversal of directory, because symbolic links may be removed. In no case will rm(1) affect the file referred to by slink.

The second rule applies to symbolic links that refer to directories. Symbolic links that refer to directories are never followed by default. This is often referred to as a "physical" walk, as opposed to a "logical" walk (where symbolic links that refer to directories are followed).

Certain conventions are (should be) followed as consistently as possible by commands that perform file tree walks:

*

A command can be made to follow any symbolic links named on the command line, regardless of the type of file they reference, by specifying the -H (for "half-logical") flag. This flag is intended to make the command-line name space look like the logical name space. (Note, for commands that do not always do file tree traversals, the -H flag will be ignored if the -R flag is not also specified.)

For example, the command chown -HR user slink will traverse the file hierarchy rooted in the file pointed to by slink. Note, the -H is not the same as the previously discussed -h flag. The -H flag causes symbolic links specified on the command line to be dereferenced for the purposes of both the action to be performed and the tree walk, and it is as if the user had specified the name of the file to which the symbolic link pointed.

*

A command can be made to follow any symbolic links named on the command line, as well as any symbolic links encountered during the traversal, regardless of the type of file they reference, by specifying the -L (for "logical") flag. This flag is intended to make the entire name space look like the logical name space. (Note, for commands that do not always do file tree traversals, the -L flag will be ignored if the -R flag is not also specified.)

For example, the command chown -LR user slink will change the owner of the file referred to by slink. If slink refers to a directory, chown will traverse the file hierarchy rooted in the directory that it references. In addition, if any symbolic links are encountered in any file tree that chown traverses, they will be treated in the same fashion as slink.

*

A command can be made to provide the default behavior by specifying the -P (for "physical") flag. This flag is intended to make the entire name space look like the physical name space.

For commands that do not by default do file tree traversals, the -H, -L, and -P flags are ignored if the -R flag is not also specified. In addition, you may specify the -H, -L, and -P options more than once; the last one specified determines the command's behavior. This is intended to permit you to alias commands to behave one way or the other, and then override that behavior on the command line.

The ls(1) and rm(1) commands have exceptions to these rules:

- The rm(1) command operates on the symbolic link, and not the file it references, and therefore never follows a symbolic link. The rm(1) command does not support the -H, -L, or -P options.

- To maintain compatibility with historic systems, the ls(1) command acts a little differently. If you do not specify the -F, -d, or -l options, ls(1) will follow symbolic links specified on the command line. If the -L flag is specified, ls(1) follows all symbolic links, regardless of their type, whether specified on the command line or encountered in the tree walk.

## SEE ALSO
chgrp(1), chmod(1), find(1), ln(1), ls(1), mv(1), namei(1), rm(1), lchown(2), link(2), lstat(2), readlink(2), rename(2), symlink(2), unlink(2), utimensat(2), lutimes(3), path_resolution(7)


package: man-pages

title: system_data_types(7)

summary: overview of system data types

text:
# system_data_types(7)

## NAME
system_data_types - overview of system data types

## DESCRIPTION
aiocb

Include: <aio.h>.

```
struct aiocb {

    int             aio_fildes;    /* File descriptor */

    off_t           aio_offset;    /* File offset */

    volatile void  *aio_buf;       /* Location of buffer */

    size_t          aio_nbytes;    /* Length of transfer */

    int             aio_reqprio;   /* Request priority offset */

    struct sigevent aio_sigevent;  /* Signal number and value */

    int             aio_lio_opcode;/* Operation to be performed */
};
```

For further information about this structure, see aio(7).

Conforming to: POSIX.1-2001 and later.

See also: aio_cancel(3), aio_error(3), aio_fsync(3), aio_read(3), aio_return(3), aio_suspend(3), aio_write(3), lio_listio(3)

blkcnt_t

Include: <sys/types.h>. Alternatively, <sys/stat.h>. Used for file block counts. According to POSIX, it shall be a signed integer type.

Conforming to: POSIX.1-2001 and later.

See also: stat(2)

blksize_t

Include: <sys/types.h>. Alternatively, <sys/stat.h>. Used for file block sizes. According to POSIX, it shall be a signed integer type.

Conforming to: POSIX.1-2001 and later.

See also: stat(2)

cc_t

Include: <termios.h>. Used for terminal special characters. According to POSIX, it shall be an unsigned integer type.

Conforming to: POSIX.1-2001 and later.

See also: termios(3)

clock_t

Include: <time.h> or <sys/types.h>. Alternatively, <sys/time.h>. Used for system time in clock ticks or CLOCKS_PER_SEC (defined in <time.h>). According to POSIX, it shall be an integer type or a real-floating type.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: times(2), clock(3)

clockid_t

Include: <sys/types.h>. Alternatively, <time.h>. Used for clock ID type in the clock and timer functions. According to POSIX, it shall be defined as an arithmetic type.

Conforming to: POSIX.1-2001 and later.

See also: clock_adjtime(2), clock_getres(2), clock_nanosleep(2), timer_create(2), clock_getcpuclockid(3)

dev_t

Include: <sys/types.h>. Alternatively, <sys/stat.h>. Used for device IDs. According to POSIX, it shall be an integer type. For further details of this type, see makedev(3).

Conforming to: POSIX.1-2001 and later.

See also: mknod(2), stat(2)

div_t

Include: <stdlib.h>.

```
typedef struct {

    int quot; /* Quotient */

    int rem;  /* Remainder */
} div_t;
```

It is the type of the value returned by the div(3) function.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: div(3)

double_t

Include: <math.h>. The implementation's most efficient floating type at least as wide as double. Its type depends on the value of the macro FLT_EVAL_METHOD (defined in <float.h>):

0

double_t is double.

1

double_t is double.

2

double_t is long double.

For other values of FLT_EVAL_METHOD, the type of double_t is implementation-defined.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the float_t type in this page.

fd_set

Include: <sys/select.h>. Alternatively, <sys/time.h>. A structure type that can represent a set of file descriptors. According to POSIX, the maximum number of file descriptors in an fd_set structure is the value of the macro FD_SETSIZE.

Conforming to: POSIX.1-2001 and later.

See also: select(2)

fenv_t

Include: <fenv.h>. This type represents the entire floating-point environment, including control modes and status flags; for further details, see fenv(3).

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: fenv(3)

fexcept_t

Include: <fenv.h>. This type represents the floating-point status flags collectively; for further details see fenv(3).

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: fenv(3)

FILE

Include: <stdio.h>. Alternatively, <wchar.h>. An object type used for streams.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: fclose(3), flockfile(3), fopen(3), fprintf(3), fread(3), fscanf(3), stdin(3), stdio(3)

float_t

Include: <math.h>. The implementation's most efficient floating type at least as wide as float. Its type depends on the value of the macro FLT_EVAL_METHOD (defined in <float.h>):

0

float_t is float.

1

float_t is double.

2

float_t is long double.

For other values of FLT_EVAL_METHOD, the type of float_t is implementation-defined.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the double_t type in this page.

gid_t

Include: <sys/types.h>. Alternatively, <grp.h>, <pwd.h>, <signal.h>, <stropts.h>, <sys/ipc.h>, <sys/stat.h>, or <unistd.h>. A type used to hold group IDs. According to POSIX, this shall be an integer type.

Conforming to: POSIX.1-2001 and later.

See also: chown(2), getgid(2), getegid(2), getgroups(2), getresgid(2), getgrnam(3), credentials(7)

id_t

Include: <sys/types.h>. Alternatively, <sys/resource.h>. A type used to hold a general identifier. According to POSIX, this shall be an integer type that can be used to contain a pid_t, uid_t, or gid_t.

Conforming to: POSIX.1-2001 and later.

See also: getpriority(2), waitid(2)

imaxdiv_t

Include: <inttypes.h>.

```
typedef struct {

    intmax_t    quot; /* Quotient */

    intmax_t    rem;  /* Remainder */
} imaxdiv_t;
```

It is the type of the value returned by the imaxdiv(3) function.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: imaxdiv(3)

intmax_t

Include: <stdint.h>. Alternatively, <inttypes.h>. A signed integer type capable of representing any value of any signed integer type supported by the implementation. According to the C language standard, it shall be capable of storing values in the range [INTMAX_MIN, INTMAX_MAX].

The macro INTMAX_C() expands its argument to an integer constant of type intmax_t.

The length modifier for intmax_t for the printf(3) and the scanf(3) families of functions is j; resulting commonly in %jd or %ji for printing intmax_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

Bugs: intmax_t is not large enough to represent values of type __int128 in implementations where __int128 is defined and long long is less than 128 bits wide.

See also: the uintmax_t type in this page.

intN_t

Include: <stdint.h>. Alternatively, <inttypes.h>. int8_t, int16_t, int32_t, int64_t

A signed integer type of a fixed width of exactly N bits, N being the value specified in its type name. According to the C language standard, they shall be capable of storing values in the range [INTN_MIN, INTN_MAX], substituting N by the appropriate number.

According to POSIX, int8_t, int16_t, and int32_t are required; int64_t is only required in implementations that provide integer types with width 64; and all other types of this form are optional.

The length modifiers for the intN_t types for the printf(3) family of functions are expanded by macros of the forms PRIdN and PRIiN (defined in <inttypes.h>); resulting for example in %"PRId64" or %"PRIi64" for printing int64_t values. The length modifiers for the intN_t types for the scanf(3) family of functions are expanded by macros of the forms SCNdN and SCNiN, (defined in <inttypes.h>); resulting for example in %"SCNd8" or %"SCNi8" for scanning int8_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the intmax_t, uintN_t, and uintmax_t types in this page.

intptr_t

Include: <stdint.h>. Alternatively, <inttypes.h>. A signed integer type such that any valid (void *) value can be converted to this type and back. According to the C language standard, it shall be capable of storing values in the range [INTPTR_MIN, INTPTR_MAX].

The length modifier for intptr_t for the printf(3) family of functions is expanded by the macros PRIdPTR and PRIiPTR (defined in <inttypes.h>); resulting commonly in %"PRIdPTR" or %"PRIiPTR" for printing intptr_t values. The length modifier for intptr_t for the scanf(3) family of functions is expanded by the macros SCNdPTR and SCNiPTR, (defined in <inttypes.h>); resulting commonly in %"SCNdPTR" or %"SCNiPTR" for scanning intptr_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the uintptr_t and void * types in this page.

lconv

Include: <locale.h>.

```
struct lconv {                  /* Values in the "C" locale: */

    char   *decimal_point;      /* "." */

    char   *thousands_sep;      /* "" */

    char   *grouping;           /* "" */

    char   *mon_decimal_point;  /* "" */

    char   *mon_thousands_sep;  /* "" */

    char   *mon_grouping;       /* "" */

    char   *positive_sign;      /* "" */

    char   *negative_sign;      /* "" */

    char   *currency_symbol;    /* "" */

    char    frac_digits;        /* CHAR_MAX */

    char    p_cs_precedes;      /* CHAR_MAX */

    char    n_cs_precedes;      /* CHAR_MAX */

    char    p_sep_by_space;     /* CHAR_MAX */

    char    n_sep_by_space;     /* CHAR_MAX */

    char    p_sign_posn;        /* CHAR_MAX */

    char    n_sign_posn;        /* CHAR_MAX */

    char   *int_curr_symbol;    /* "" */

    char    int_frac_digits;    /* CHAR_MAX */

    char    int_p_cs_precedes;  /* CHAR_MAX */

    char    int_n_cs_precedes;  /* CHAR_MAX */

    char    int_p_sep_by_space; /* CHAR_MAX */

    char    int_n_sep_by_space; /* CHAR_MAX */

    char    int_p_sign_posn;    /* CHAR_MAX */

    char    int_n_sign_posn;    /* CHAR_MAX */
};
```

Contains members related to the formatting of numeric values. In the "C" locale, its members have the values shown in the comments above.

Conforming to: C11 and later; POSIX.1-2001 and later.

See also: setlocale(3), localeconv(3), charsets(7), locale(7)

ldiv_t

Include: <stdlib.h>.

```
typedef struct {

    long    quot; /* Quotient */

    long    rem;  /* Remainder */
} ldiv_t;
```

It is the type of the value returned by the ldiv(3) function.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: ldiv(3)

lldiv_t

Include: <stdlib.h>.

```
typedef struct {

    long long   quot; /* Quotient */

    long long   rem;  /* Remainder */
} lldiv_t;
```

It is the type of the value returned by the lldiv(3) function.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: lldiv(3)

mode_t

Include: <sys/types.h>. Alternatively, <fcntl.h>, <ndbm.h>, <spawn.h>, <sys/ipc.h>, <sys/mman.h>, or <sys/stat.h>. Used for some file attributes (e.g., file mode). According to POSIX, it shall be an integer type.

Conforming to: POSIX.1-2001 and later.

See also: chmod(2), mkdir(2), open(2), stat(2), umask(2)

off64_t

Include: <sys/types.h>. Used for file sizes. It is a 64-bit signed integer type.

Conforming to: Present in glibc. It is not standardized by the C language standard nor POSIX.

Notes: The feature test macro _LARGEFILE64_SOURCE has to be defined for this type to be available.

See also: copy_file_range(2), readahead(2), sync_file_range(2), lseek64(3), feature_test_macros(7)

See also the off_t type in this page.

off_t

Include: <sys/types.h>. Alternatively, <aio.h>, <fcntl.h>, <stdio.h>, <sys/mman.h>, <sys/stat.h.h>, or <unistd.h>. Used for file sizes. According to POSIX, this shall be a signed integer type.

Versions: <aio.h> and <stdio.h> define off_t since POSIX.1-2008.

Conforming to: POSIX.1-2001 and later.

Notes: On some architectures, the width of this type can be controlled with the feature test macro _FILE_OFFSET_BITS.

See also: lseek(2), mmap(2), posix_fadvise(2), pread(2), truncate(2), fseeko(3), lockf(3), posix_fallocate(3), feature_test_macros(7)

See also the off64_t type in this page.

pid_t

Include: <sys/types.h>. Alternatively, <fcntl.h>, <sched.h>, <signal.h>, <spawn.h>, <sys/msg.h>, <sys/sem.h>, <sys/shm.h>, <sys/wait.h>, <termios.h>, <time.h>, <unistd.h>, or <utmpx.h>. This type is used for storing process IDs, process group IDs, and session IDs. According to POSIX, it shall be a signed integer type, and the implementation shall support one or more programming environments where the width of pid_t is no greater than the width of the type long.

Conforming to: POSIX.1-2001 and later.

See also: fork(2), getpid(2), getppid(2), getsid(2), gettid(2), getpgid(2), kill(2), pidfd_open(2), sched_setscheduler(2), waitpid(2), sigqueue(3), credentials(7),

ptrdiff_t

Include: <stddef.h>. Used for a count of elements, and array indices. It is the result of subtracting two pointers. According to the C language standard, it shall be a signed integer type capable of storing values in the range [PTRDIFF_MIN, PTRDIFF_MAX].

The length modifier for ptrdiff_t for the printf(3) and the scanf(3) families of functions is t; resulting commonly in %td or %ti for printing ptrdiff_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the size_t and ssize_t types in this page.

regex_t

Include: <regex.h>.

```
typedef struct {

    size_t  re_nsub; /* Number of parenthesized subexpressions */
} regex_t;
```

This is a structure type used in regular expression matching. It holds a compiled regular expression, compiled with regcomp(3).

Conforming to: POSIX.1-2001 and later.

See also: regex(3)

regmatch_t

Include: <regex.h>.

```
typedef struct {

    regoff_t    rm_so; /* Byte offset from start of string

                          to start of substring */

    regoff_t    rm_eo; /* Byte offset from start of string of

                          the first character after the end of

                          substring */
} regmatch_t;
```

This is a structure type used in regular expression matching.

Conforming to: POSIX.1-2001 and later.

See also: regexec(3)

regoff_t

Include: <regex.h>. According to POSIX, it shall be a signed integer type capable of storing the largest value that can be stored in either a ptrdiff_t type or a ssize_t type.

Versions: Prior to POSIX.1-2008, the type was capable of storing the largest value that can be stored in either an off_t type or a ssize_t type.

Conforming to: POSIX.1-2001 and later.

See also: the regmatch_t structure and the ptrdiff_t and ssize_t types in this page.

sigevent

Include: <signal.h>. Alternatively, <aio.h>, <mqueue.h>, or <time.h>.

```
struct sigevent {

    int             sigev_notify; /* Notification type */

    int             sigev_signo;  /* Signal number */

    union sigval    sigev_value;  /* Signal value */

    void          (*sigev_notify_function)(union sigval);

                                  /* Notification function */

    pthread_attr_t *sigev_notify_attributes;

                                  /* Notification attributes */
};
```

For further details about this type, see sigevent(7).

Versions: <aio.h> and <time.h> define sigevent since POSIX.1-2008.

Conforming to: POSIX.1-2001 and later.

See also: timer_create(2), getaddrinfo_a(3), lio_listio(3), mq_notify(3)

See also the aiocb structure in this page.

siginfo_t

Include: <signal.h>. Alternatively, <sys/wait.h>.

```
typedef struct {

    int      si_signo;  /* Signal number */

    int      si_code;   /* Signal code */

    pid_t    si_pid;    /* Sending process ID */

    uid_t    si_uid;    /* Real user ID of sending process */

    void    *si_addr;   /* Address of faulting instruction */

    int      si_status; /* Exit value or signal */

    union sigval si_value;  /* Signal value */
} siginfo_t;
```

Information associated with a signal. For further details on this structure (including additional, Linux-specific fields), see sigaction(2).

Conforming to: POSIX.1-2001 and later.

See also: pidfd_send_signal(2), rt_sigqueueinfo(2), sigaction(2), sigwaitinfo(2), psiginfo(3)

sigset_t

Include: <signal.h>. Alternatively, <spawn.h>, or <sys/select.h>. This is a type that represents a set of signals. According to POSIX, this shall be an integer or structure type.

Conforming to: POSIX.1-2001 and later.

See also: epoll_pwait(2), ppoll(2), pselect(2), sigaction(2), signalfd(2), sigpending(2), sigprocmask(2), sigsuspend(2), sigwaitinfo(2), signal(7)

sigval

Include: <signal.h>.

```
union sigval {

    int     sigval_int; /* Integer value */

    void   *sigval_ptr; /* Pointer value */
};
```

Data passed with a signal.

Conforming to: POSIX.1-2001 and later.

See also: pthread_sigqueue(3), sigqueue(3), sigevent(7)

See also the sigevent structure and the siginfo_t type in this page.

size_t

Include: <stddef.h> or <sys/types.h>. Alternatively, <aio.h>, <glob.h>, <grp.h>, <iconv.h>, <monetary.h>, <mqueue.h>, <ndbm.h>, <pwd.h>, <regex.h>, <search.h>, <signal.h>, <stdio.h>, <stdlib.h>, <string.h>, <strings.h>, <sys/mman.h>, <sys/msg.h>, <sys/sem.h>, <sys/shm.h>, <sys/socket.h>, <sys/uio.h>, <time.h>, <unistd.h>, <wchar.h>, or <wordexp.h>. Used for a count of bytes. It is the result of the sizeof operator. According to the C language standard, it shall be an unsigned integer type capable of storing values in the range [0, SIZE_MAX]. According to POSIX, the implementation shall support one or more programming environments where the width of size_t is no greater than the width of the type long.

The length modifier for size_t for the printf(3) and the scanf(3) families of functions is z; resulting commonly in %zu or %zx for printing size_t values.

Versions: <aio.h>, <glob.h>, <grp.h>, <iconv.h>, <mqueue.h>, <pwd.h>, <signal.h>, and <sys/socket.h> define size_t since POSIX.1-2008.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: read(2), write(2), fread(3), fwrite(3), memcmp(3), memcpy(3), memset(3), offsetof(3)

See also the ptrdiff_t and ssize_t types in this page.

sockaddr

Include: <sys/socket.h>.

```
struct sockaddr {

    sa_family_t sa_family; /* Address family */

    char        sa_data[]; /* Socket address */
};
```

Describes a socket address.

Conforming to: POSIX.1-2001 and later.

See also: accept(2), getpeername(2), getsockname(2), socket(2)

socklen_t

Include: <sys/socket.h>. Alternatively, <netdb.h>. Describes the length of a socket address. According to POSIX, this shall be an integer type of at least 32 bits.

Conforming to: POSIX.1-2001 and later.

See also: accept(2), bind(2), connect(2), gethostbyaddr(2), getnameinfo(2), socket(2)

See also the sockaddr structure in this page.

ssize_t

Include: <sys/types.h>. Alternatively, <aio.h>, <monetary.h>, <mqueue.h>, <stdio.h>, <sys/msg.h>, <sys/socket.h>, <sys/uio.h>, or <unistd.h>. Used for a count of bytes or an error indication. According to POSIX, it shall be a signed integer type capable of storing values at least in the range [-1, SSIZE_MAX], and the implementation shall support one or more programming environments where the width of ssize_t is no greater than the width of the type long.

Glibc and most other implementations provide a length modifier for ssize_t for the printf(3) and the scanf(3) families of functions, which is z; resulting commonly in %zd or %zi for printing ssize_t values. Although z works for ssize_t on most implementations, portable POSIX programs should avoid using it—for example, by converting the value to intmax_t and using its length modifier (j).

Conforming to: POSIX.1-2001 and later.

See also: read(2), readlink(2), readv(2), recv(2), send(2), write(2)

See also the ptrdiff_t and size_t types in this page.

suseconds_t

Include: <sys/types.h>. Alternatively, <sys/select.h>, or <sys/time.h>. Used for time in microseconds. According to POSIX, it shall be a signed integer type capable of storing values at least in the range [-1, 1000000], and the implementation shall support one or more programming environments where the width of suseconds_t is no greater than the width of the type long.

Conforming to: POSIX.1-2001 and later.

See also: the timeval structure in this page.

time_t

Include: <time.h> or <sys/types.h>. Alternatively, <sched.h>, <sys/msg.h>, <sys/select.h>, <sys/sem.h>, <sys/shm.h>, <sys/stat.h>, <sys/time.h>, or <utime.h>. Used for time in seconds. According to POSIX, it shall be an integer type.

Versions: <sched.h> defines time_t since POSIX.1-2008.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: stime(2), time(2), ctime(3), difftime(3)

timer_t

Include: <sys/types.h>. Alternatively, <time.h>. Used for timer ID returned by timer_create(2). According to POSIX, there are no defined comparison or assignment operators for this type.

Conforming to: POSIX.1-2001 and later.

See also: timer_create(2), timer_delete(2), timer_getoverrun(2), timer_settime(2)

timespec

Include: <time.h>. Alternatively, <aio.h>, <mqueue.h>, <sched.h>, <signal.h>, <sys/select.h>, or <sys/stat.h>.

```
struct timespec {

    time_t  tv_sec;  /* Seconds */

    long    tv_nsec; /* Nanoseconds */
};
```

Describes times in seconds and nanoseconds.

Conforming to: C11 and later; POSIX.1-2001 and later.

See also: clock_gettime(2), clock_nanosleep(2), nanosleep(2), timerfd_gettime(2), timer_gettime(2)

timeval

Include: <sys/time.h>. Alternatively, <sys/resource.h>, <sys/select.h>, or <utmpx.h>.

```
struct timeval {

    time_t      tv_sec;  /* Seconds */

    suseconds_t tv_usec; /* Microseconds */
};
```

Describes times in seconds and microseconds.

Conforming to: POSIX.1-2001 and later.

See also: gettimeofday(2), select(2), utimes(2), adjtime(3), futimes(3), timeradd(3)

uid_t

Include: <sys/types.h>. Alternatively, <pwd.h>, <signal.h>, <stropts.h>, <sys/ipc.h>, <sys/stat.h>, or <unistd.h>. A type used to hold user IDs. According to POSIX, this shall be an integer type.

Conforming to: POSIX.1-2001 and later.

See also: chown(2), getuid(2), geteuid(2), getresuid(2), getpwnam(3), credentials(7)

uintmax_t

Include: <stdint.h>. Alternatively, <inttypes.h>. An unsigned integer type capable of representing any value of any unsigned integer type supported by the implementation. According to the C language standard, it shall be capable of storing values in the range [0, UINTMAX_MAX].

The macro UINTMAX_C() expands its argument to an integer constant of type uintmax_t.

The length modifier for uintmax_t for the printf(3) and the scanf(3) families of functions is j; resulting commonly in %ju or %jx for printing uintmax_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

Bugs: uintmax_t is not large enough to represent values of type unsigned __int128 in implementations where unsigned __int128 is defined and unsigned long long is less than 128 bits wide.

See also: the intmax_t type in this page.

uintN_t

Include: <stdint.h>. Alternatively, <inttypes.h>. uint8_t, uint16_t, uint32_t, uint64_t

An unsigned integer type of a fixed width of exactly N bits, N being the value specified in its type name. According to the C language standard, they shall be capable of storing values in the range [0, UINTN_MAX], substituting N by the appropriate number.

According to POSIX, uint8_t, uint16_t, and uint32_t are required; uint64_t is only required in implementations that provide integer types with width 64; and all other types of this form are optional.

The length modifiers for the uintN_t types for the printf(3) family of functions are expanded by macros of the forms PRIuN, PRIoN, PRIxN, and PRIXN (defined in <inttypes.h>); resulting for example in %"PRIu32" or %"PRIx32" for printing uint32_t values. The length modifiers for the uintN_t types for the scanf(3) family of functions are expanded by macros of the forms SCNuN, SCNoN, SCNxN, and SCNXN (defined in <inttypes.h>); resulting for example in %"SCNu16" or %"SCNx16" for scanning uint16_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the intmax_t, intN_t, and uintmax_t types in this page.

uintptr_t

Include: <stdint.h>. Alternatively, <inttypes.h>. An unsigned integer type such that any valid (void *) value can be converted to this type and back. According to the C language standard, it shall be capable of storing values in the range [0, UINTPTR_MAX].

The length modifier for uintptr_t for the printf(3) family of functions is expanded by the macros PRIuPTR, PRIoPTR, PRIxPTR, and PRIXPTR (defined in <inttypes.h>); resulting commonly in %"PRIuPTR" or %"PRIxPTR" for printing uintptr_t values. The length modifier for uintptr_t for the scanf(3) family of functions is expanded by the macros SCNuPTR, SCNoPTR, SCNxPTR, and SCNXPTR (defined in <inttypes.h>); resulting commonly in %"SCNuPTR" or %"SCNxPTR" for scanning uintptr_t values.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: the intptr_t and void * types in this page.

va_list

Include: <stdarg>. Alternatively, <stdio.h>, or <wchar.h>. Used by functions with a varying number of arguments of varying types. The function must declare an object of type va_list which is used by the macros va_start(3), va_arg(3), va_copy(3), and va_end(3) to traverse the list of arguments.

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: va_start(3), va_arg(3), va_copy(3), va_end(3)

void *

According to the C language standard, a pointer to any object type may be converted to a pointer to void and back. POSIX further requires that any pointer, including pointers to functions, may be converted to a pointer to void and back. Conversions from and to any other pointer type are done implicitly, not requiring casts at all. Note that this feature prevents any kind of type checking: the programmer should be careful not to convert a void * value to a type incompatible to that of the underlying data, because that would result in undefined behavior.

This type is useful in function parameters and return value to allow passing values of any type. The function will typically use some mechanism to know the real type of the data being passed via a pointer to void.

A value of this type can't be dereferenced, as it would give a value of type void, which is not possible. Likewise, pointer arithmetic is not possible with this type. However, in GNU C, pointer arithmetic is allowed as an extension to the standard; this is done by treating the size of a void or of a function as 1. A consequence of this is that sizeof is also allowed on void and on function types, and returns 1.

The conversion specifier for void * for the printf(3) and the scanf(3) families of functions is p.

Versions: The POSIX requirement about compatibility between void * and function pointers was added in POSIX.1-2008 Technical Corrigendum 1 (2013).

Conforming to: C99 and later; POSIX.1-2001 and later.

See also: malloc(3), memcmp(3), memcpy(3), memset(3)

See also the intptr_t and uintptr_t types in this page.

## NOTES
The structures described in this manual page shall contain, at least, the members shown in their definition, in no particular order.

Most of the integer types described in this page don't have a corresponding length modifier for the printf(3) and the scanf(3) families of functions. To print a value of an integer type that doesn't have a length modifier, it should be converted to intmax_t or uintmax_t by an explicit cast. To scan into a variable of an integer type that doesn't have a length modifier, an intermediate temporary variable of type intmax_t or uintmax_t should be used. When copying from the temporary variable to the destination variable, the value could overflow. If the type has upper and lower limits, the user should check that the value is within those limits, before actually copying the value. The example below shows how these conversions should be done.

### Conventions used in this page
In "Conforming to" we only concern ourselves with C99 and later and POSIX.1-2001 and later. Some types may be specified in earlier versions of one of these standards, but in the interests of simplicity we omit details from earlier standards.

In "Include", we first note the "primary" header(s) that define the type according to either the C or POSIX.1 standards. Under "Alternatively", we note additional headers that the standards specify shall define the type.

## EXAMPLES
The program shown below scans from a string and prints a value stored in a variable of an integer type that doesn't have a length modifier. The appropriate conversions from and to intmax_t, and the appropriate range checks, are used as explained in the notes section above.

```
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int
main (void)
{

    static const char *const str = "500000 us in half a second";

    suseconds_t us;

    intmax_t    tmp;

    /* Scan the number from the string into the temporary variable. */

    sscanf(str, "%jd", &tmp);

    /* Check that the value is within the valid range of suseconds_t. */

    if (tmp < -1 || tmp > 1000000) {

        fprintf(stderr, "Scanned value outside valid range!\n");

        exit(EXIT_FAILURE);

    }

    /* Copy the value to the suseconds_t variable 'us'. */

    us = tmp;

    /* Even though suseconds_t can hold the value -1, this isn't

       a sensible number of microseconds. */

    if (us < 0) {

        fprintf(stderr, "Scanned value shouldn't be negative!\n");

        exit(EXIT_FAILURE);

    }

    /* Print the value. */

    printf("There are %jd microseconds in half a second.\n",

            (intmax_t) us);

    exit(EXIT_SUCCESS);
}
```

## SEE ALSO
feature_test_macros(7), standards(7)


sysvipc

title: sysvipc(7)

text:
# sysvipc(7)

## NAME
sysvipc - System V interprocess communication mechanisms

## DESCRIPTION
System V IPC is the name given to three interprocess communication mechanisms that are widely available on UNIX systems: message queues, semaphore, and shared memory.

### Message queues
System V message queues allow data to be exchanged in units called messages. Each messages can have an associated priority, POSIX message queues provide an alternative API for achieving the same result; see mq_overview(7).

The System V message queue API consists of the following system calls:

msgget(2)

Create a new message queue or obtain the ID of an existing message queue. This call returns an identifier that is used in the remaining APIs.

msgsnd(2)

Add a message to a queue.

msgrcv(2)

Remove a message from a queue.

msgctl(2)

Perform various control operations on a queue, including deletion.

### Semaphore sets
System V semaphores allow processes to synchronize their actions System V semaphores are allocated in groups called sets; each semaphore in a set is a counting semaphore. POSIX semaphores provide an alternative API for achieving the same result; see sem_overview(7).

The System V semaphore API consists of the following system calls:

semget(2)

Create a new set or obtain the ID of an existing set. This call returns an identifier that is used in the remaining APIs.

semop(2)

Perform operations on the semaphores in a set.

semctl(2)

Perform various control operations on a set, including deletion.

### Shared memory segments
System V shared memory allows processes to share a region a memory (a "segment"). POSIX shared memory is an alternative API for achieving the same result; see shm_overview(7).

The System V shared memory API consists of the following system calls:

shmget(2)

Create a new segment or obtain the ID of an existing segment. This call returns an identifier that is used in the remaining APIs.

shmat(2)

Attach an existing shared memory object into the calling process's address space.

shmdt(2)

Detach a segment from the calling process's address space.

shmctl(2)

Perform various control operations on a segment, including deletion.

### IPC namespaces
For a discussion of the interaction of System V IPC objects and IPC namespaces, see ipc_namespaces(7).

## SEE ALSO
ipcmk(1), ipcrm(1), ipcs(1), lsipc(1), ipc(2), msgctl(2), msgget(2), msgrcv(2), msgsnd(2), semctl(2), semget(2), semop(2), shmat(2), shmctl(2), shmdt(2), shmget(2), ftok(3), ipc_namespaces(7)


tcp

title: tcp(7)

summary: TCP protocol

text:
# tcp(7)

## NAME
tcp - TCP protocol

## SYNOPSIS

```
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
```

```
tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
```

## DESCRIPTION
This is an implementation of the TCP protocol defined in RFC 793, RFC 1122 and RFC 2001 with the NewReno and SACK extensions. It provides a reliable, stream-oriented, full-duplex connection between two sockets on top of ip(7), for both v4 and v6 versions. TCP guarantees that the data arrives in order and retransmits lost packets. It generates and checks a per-packet checksum to catch transmission errors. TCP does not preserve record boundaries.

A newly created TCP socket has no remote or local address and is not fully specified. To create an outgoing TCP connection use connect(2) to establish a connection to another TCP socket. To receive new incoming connections, first bind(2) the socket to a local address and port and then call listen(2) to put the socket into the listening state. After that a new socket for each incoming connection can be accepted using accept(2). A socket which has had accept(2) or connect(2) successfully called on it is fully specified and may transmit data. Data cannot be transmitted on listening or not yet connected sockets.

Linux supports RFC 1323 TCP high performance extensions. These include Protection Against Wrapped Sequence Numbers (PAWS), Window Scaling and Timestamps. Window scaling allows the use of large (> 64 kB) TCP windows in order to support links with high latency or bandwidth. To make use of them, the send and receive buffer sizes must be increased. They can be set globally with the /proc/sys/net/ipv4/tcp_wmem and /proc/sys/net/ipv4/tcp_rmem files, or on individual sockets by using the SO_SNDBUF and SO_RCVBUF socket options with the setsockopt(2) call.

The maximum sizes for socket buffers declared via the SO_SNDBUF and SO_RCVBUF mechanisms are limited by the values in the /proc/sys/net/core/rmem_max and /proc/sys/net/core/wmem_max files. Note that TCP actually allocates twice the size of the buffer requested in the setsockopt(2) call, and so a succeeding getsockopt(2) call will not return the same size of buffer as requested in the setsockopt(2) call. TCP uses the extra space for administrative purposes and internal kernel structures, and the /proc file values reflect the larger sizes compared to the actual TCP windows. On individual connections, the socket buffer size must be set prior to the listen(2) or connect(2) calls in order to have it take effect. See socket(7) for more information.

TCP supports urgent data. Urgent data is used to signal the receiver that some important message is part of the data stream and that it should be processed as soon as possible. To send urgent data specify the MSG_OOB option to send(2). When urgent data is received, the kernel sends a SIGURG signal to the process or process group that has been set as the socket "owner" using the SIOCSPGRP or FIOSETOWN ioctls (or the POSIX.1-specified fcntl(2) F_SETOWN operation). When the SO_OOBINLINE socket option is enabled, urgent data is put into the normal data stream (a program can test for its location using the SIOCATMARK ioctl described below), otherwise it can be received only when the MSG_OOB flag is set for recv(2) or recvmsg(2).

When out-of-band data is present, select(2) indicates the file descriptor as having an exceptional condition and poll (2) indicates a POLLPRI event.

Linux 2.4 introduced a number of changes for improved throughput and scaling, as well as enhanced functionality. Some of these features include support for zero-copy sendfile(2), Explicit Congestion Notification, new management of TIME_WAIT sockets, keep-alive socket options and support for Duplicate SACK extensions.

### Address formats
TCP is built on top of IP (see ip(7)). The address formats defined by ip(7) apply to TCP. TCP supports point-to-point communication only; broadcasting and multicasting are not supported.

### /proc interfaces
System-wide TCP parameter settings can be accessed by files in the directory /proc/sys/net/ipv4/. In addition, most IP /proc interfaces also apply to TCP; see ip(7). Variables described as Boolean take an integer value, with a nonzero value ("true") meaning that the corresponding option is enabled, and a zero value ("false") meaning that the option is disabled.

tcp_abc (Integer; default: 0; Linux 2.6.15 to Linux 3.8)

Control the Appropriate Byte Count (ABC), defined in RFC 3465. ABC is a way of increasing the congestion window (cwnd) more slowly in response to partial acknowledgements. Possible values are:

0

increase cwnd once per acknowledgement (no ABC)

1

increase cwnd once per acknowledgement of full sized segment

2

allow increase cwnd by two if acknowledgement is of two segments to compensate for delayed acknowledgements.

tcp_abort_on_overflow (Boolean; default: disabled; since Linux 2.4)

Enable resetting connections if the listening service is too slow and unable to keep up and accept them. It means that if overflow occurred due to a burst, the connection will recover. Enable this option only if you are really sure that the listening daemon cannot be tuned to accept connections faster. Enabling this option can harm the clients of your server.

tcp_adv_win_scale (integer; default: 2; since Linux 2.4)

Count buffering overhead as bytes/2^tcp_adv_win_scale, if tcp_adv_win_scale is greater than 0; or bytes-bytes/2^(-tcp_adv_win_scale), if tcp_adv_win_scale is less than or equal to zero.

The socket receive buffer space is shared between the application and kernel. TCP maintains part of the buffer as the TCP window, this is the size of the receive window advertised to the other end. The rest of the space is used as the "application" buffer, used to isolate the network from scheduling and application latencies. The tcp_adv_win_scale default value of 2 implies that the space used for the application buffer is one fourth that of the total.

tcp_allowed_congestion_control (String; default: see text; since Linux 2.4.20)

Show/set the congestion control algorithm choices available to unprivileged processes (see the description of the TCP_CONGESTION socket option). The items in the list are separated by white space and terminated by a newline character. The list is a subset of those listed in tcp_available_congestion_control. The default value for this list is "reno" plus the default setting of tcp_congestion_control.

tcp_autocorking (Boolean; default: enabled; since Linux 3.14)

If this option is enabled, the kernel tries to coalesce small writes (from consecutive write(2) and sendmsg(2) calls) as much as possible, in order to decrease the total number of sent packets. Coalescing is done if at least one prior packet for the flow is waiting in Qdisc queues or device transmit queue. Applications can still use the TCP_CORK socket option to obtain optimal behavior when they know how/when to uncork their sockets.

tcp_available_congestion_control (String; read-only; since Linux 2.4.20)

Show a list of the congestion-control algorithms that are registered. The items in the list are separated by white space and terminated by a newline character. This list is a limiting set for the list in tcp_allowed_congestion_control. More congestion-control algorithms may be available as modules, but not loaded.

tcp_app_win (integer; default: 31; since Linux 2.4)

This variable defines how many bytes of the TCP window are reserved for buffering overhead.

A maximum of (window/2^tcp_app_win, mss) bytes in the window are reserved for the application buffer. A value of 0 implies that no amount is reserved.

tcp_base_mss (Integer; default: 512; since Linux 2.6.17)

The initial value of search_low to be used by the packetization layer Path MTU discovery (MTU probing). If MTU probing is enabled, this is the initial MSS used by the connection.

tcp_bic (Boolean; default: disabled; Linux 2.4.27/2.6.6 to 2.6.13)

Enable BIC TCP congestion control algorithm. BIC-TCP is a sender-side-only change that ensures a linear RTT fairness under large windows while offering both scalability and bounded TCP-friendliness. The protocol combines two schemes called additive increase and binary search increase. When the congestion window is large, additive increase with a large increment ensures linear RTT fairness as well as good scalability. Under small congestion windows, binary search increase provides TCP friendliness.

tcp_bic_low_window (integer; default: 14; Linux 2.4.27/2.6.6 to 2.6.13)

Set the threshold window (in packets) where BIC TCP starts to adjust the congestion window. Below this threshold BIC TCP behaves the same as the default TCP Reno.

tcp_bic_fast_convergence (Boolean; default: enabled; Linux 2.4.27/2.6.6 to 2.6.13)

Force BIC TCP to more quickly respond to changes in congestion window. Allows two flows sharing the same connection to converge more rapidly.

tcp_congestion_control (String; default: see text; since Linux 2.4.13)

Set the default congestion-control algorithm to be used for new connections. The algorithm "reno" is always available, but additional choices may be available depending on kernel configuration. The default value for this file is set as part of kernel configuration.

tcp_dma_copybreak (integer; default: 4096; since Linux 2.6.24)

Lower limit, in bytes, of the size of socket reads that will be offloaded to a DMA copy engine, if one is present in the system and the kernel was configured with the CONFIG_NET_DMA option.

tcp_dsack (Boolean; default: enabled; since Linux 2.4)

Enable RFC 2883 TCP Duplicate SACK support.

tcp_ecn (Integer; default: see below; since Linux 2.4)

Enable RFC 3168 Explicit Congestion Notification.

This file can have one of the following values:

0

Disable ECN. Neither initiate nor accept ECN. This was the default up to and including Linux 2.6.30.

1

Enable ECN when requested by incoming connections and also request ECN on outgoing connection attempts.

2

Enable ECN when requested by incoming connections, but do not request ECN on outgoing connections. This value is supported, and is the default, since Linux 2.6.31.

When enabled, connectivity to some destinations could be affected due to older, misbehaving middle boxes along the path, causing connections to be dropped. However, to facilitate and encourage deployment with option 1, and to work around such buggy equipment, the tcp_ecn_fallback option has been introduced.

tcp_ecn_fallback (Boolean; default: enabled; since Linux 4.1)

Enable RFC 3168, Section 6.1.1.1. fallback. When enabled, outgoing ECN-setup SYNs that time out within the normal SYN retransmission timeout will be resent with CWR and ECE cleared.

tcp_fack (Boolean; default: enabled; since Linux 2.2)

Enable TCP Forward Acknowledgement support.

tcp_fin_timeout (integer; default: 60; since Linux 2.2)

This specifies how many seconds to wait for a final FIN packet before the socket is forcibly closed. This is strictly a violation of the TCP specification, but required to prevent denial-of-service attacks. In Linux 2.2, the default value was 180.

tcp_frto (integer; default: see below; since Linux 2.4.21/2.6)

Enable F-RTO, an enhanced recovery algorithm for TCP retransmission timeouts (RTOs). It is particularly beneficial in wireless environments where packet loss is typically due to random radio interference rather than intermediate router congestion. See RFC 4138 for more details.

This file can have one of the following values:

0

Disabled. This was the default up to and including Linux 2.6.23.

1

The basic version F-RTO algorithm is enabled.

2

Enable SACK-enhanced F-RTO if flow uses SACK. The basic version can be used also when SACK is in use though in that case scenario(s) exists where F-RTO interacts badly with the packet counting of the SACK-enabled TCP flow. This value is the default since Linux 2.6.24.

Before Linux 2.6.22, this parameter was a Boolean value, supporting just values 0 and 1 above.

tcp_frto_response (integer; default: 0; since Linux 2.6.22)

When F-RTO has detected that a TCP retransmission timeout was spurious (i.e., the timeout would have been avoided had TCP set a longer retransmission timeout), TCP has several options concerning what to do next. Possible values are:

0

Rate halving based; a smooth and conservative response, results in halved congestion window (cwnd) and slow-start threshold (ssthresh) after one RTT.

1

Very conservative response; not recommended because even though being valid, it interacts poorly with the rest of Linux TCP; halves cwnd and ssthresh immediately.

2

Aggressive response; undoes congestion-control measures that are now known to be unnecessary (ignoring the possibility of a lost retransmission that would require TCP to be more cautious); cwnd and ssthresh are restored to the values prior to timeout.

tcp_keepalive_intvl (integer; default: 75; since Linux 2.4)

The number of seconds between TCP keep-alive probes.

tcp_keepalive_probes (integer; default: 9; since Linux 2.2)

The maximum number of TCP keep-alive probes to send before giving up and killing the connection if no response is obtained from the other end.

tcp_keepalive_time (integer; default: 7200; since Linux 2.2)

The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are sent only when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours). An idle connection is terminated after approximately an additional 11 minutes (9 probes an interval of 75 seconds apart) when keep-alive is enabled.

Note that underlying connection tracking mechanisms and application timeouts may be much shorter.

tcp_low_latency (Boolean; default: disabled; since Linux 2.4.21/2.6; obsolete since Linux 4.14)

If enabled, the TCP stack makes decisions that prefer lower latency as opposed to higher throughput. It this option is disabled, then higher throughput is preferred. An example of an application where this default should be changed would be a Beowulf compute cluster. Since Linux 4.14, this file still exists, but its value is ignored.

tcp_max_orphans (integer; default: see below; since Linux 2.4)

The maximum number of orphaned (not attached to any user file handle) TCP sockets allowed in the system. When this number is exceeded, the orphaned connection is reset and a warning is printed. This limit exists only to prevent simple denial-of-service attacks. Lowering this limit is not recommended. Network conditions might require you to increase the number of orphans allowed, but note that each orphan can eat up to ~64 kB of unswappable memory. The default initial value is set equal to the kernel parameter NR_FILE. This initial default is adjusted depending on the memory in the system.

tcp_max_syn_backlog (integer; default: see below; since Linux 2.2)

The maximum number of queued connection requests which have still not received an acknowledgement from the connecting client. If this number is exceeded, the kernel will begin dropping requests. The default value of 256 is increased to 1024 when the memory present in the system is adequate or greater (>= 128 MB), and reduced to 128 for those systems with very low memory (<= 32 MB).

Prior to Linux 2.6.20, it was recommended that if this needed to be increased above 1024, the size of the SYNACK hash table (TCP_SYNQ_HSIZE) in include/net/tcp.h should be modified to keep

TCP_SYNQ_HSIZE * 16 <= tcp_max_syn_backlog

and the kernel should be recompiled. In Linux 2.6.20, the fixed sized TCP_SYNQ_HSIZE was removed in favor of dynamic sizing.

tcp_max_tw_buckets (integer; default: see below; since Linux 2.4)

The maximum number of sockets in TIME_WAIT state allowed in the system. This limit exists only to prevent simple denial-of-service attacks. The default value of NR_FILE*2 is adjusted depending on the memory in the system. If this number is exceeded, the socket is closed and a warning is printed.

tcp_moderate_rcvbuf (Boolean; default: enabled; since Linux 2.4.17/2.6.7)

If enabled, TCP performs receive buffer auto-tuning, attempting to automatically size the buffer (no greater than tcp_rmem[2]) to match the size required by the path for full throughput.

tcp_mem (since Linux 2.4)

This is a vector of 3 integers: [low, pressure, high]. These bounds, measured in units of the system page size, are used by TCP to track its memory usage. The defaults are calculated at boot time from the amount of available memory. (TCP can only use low memory for this, which is limited to around 900 megabytes on 32-bit systems. 64-bit systems do not suffer this limitation.)

low

TCP doesn't regulate its memory allocation when the number of pages it has allocated globally is below this number.

pressure

When the amount of memory allocated by TCP exceeds this number of pages, TCP moderates its memory consumption. This memory pressure state is exited once the number of pages allocated falls below the low mark.

high

The maximum number of pages, globally, that TCP will allocate. This value overrides any other limits imposed by the kernel.

tcp_mtu_probing (integer; default: 0; since Linux 2.6.17)

This parameter controls TCP Packetization-Layer Path MTU Discovery. The following values may be assigned to the file:

0

Disabled

1

Disabled by default, enabled when an ICMP black hole detected

2

Always enabled, use initial MSS of tcp_base_mss.

tcp_no_metrics_save (Boolean; default: disabled; since Linux 2.6.6)

By default, TCP saves various connection metrics in the route cache when the connection closes, so that connections established in the near future can use these to set initial conditions. Usually, this increases overall performance, but it may sometimes cause performance degradation. If tcp_no_metrics_save is enabled, TCP will not cache metrics on closing connections.

tcp_orphan_retries (integer; default: 8; since Linux 2.4)

The maximum number of attempts made to probe the other end of a connection which has been closed by our end.

tcp_reordering (integer; default: 3; since Linux 2.4)

The maximum a packet can be reordered in a TCP packet stream without TCP assuming packet loss and going into slow start. It is not advisable to change this number. This is a packet reordering detection metric designed to minimize unnecessary back off and retransmits provoked by reordering of packets on a connection.

tcp_retrans_collapse (Boolean; default: enabled; since Linux 2.2)

Try to send full-sized packets during retransmit.

tcp_retries1 (integer; default: 3; since Linux 2.2)

The number of times TCP will attempt to retransmit a packet on an established connection normally, without the extra effort of getting the network layers involved. Once we exceed this number of retransmits, we first have the network layer update the route if possible before each new retransmit. The default is the RFC specified minimum of 3.

tcp_retries2 (integer; default: 15; since Linux 2.2)

The maximum number of times a TCP packet is retransmitted in established state before giving up. The default value is 15, which corresponds to a duration of approximately between 13 to 30 minutes, depending on the retransmission timeout. The RFC 1122 specified minimum limit of 100 seconds is typically deemed too short.

tcp_rfc1337 (Boolean; default: disabled; since Linux 2.2)

Enable TCP behavior conformant with RFC 1337. When disabled, if a RST is received in TIME_WAIT state, we close the socket immediately without waiting for the end of the TIME_WAIT period.

tcp_rmem (since Linux 2.4)

This is a vector of 3 integers: [min, default, max]. These parameters are used by TCP to regulate receive buffer sizes. TCP dynamically adjusts the size of the receive buffer from the defaults listed below, in the range of these values, depending on memory available in the system.

min

minimum size of the receive buffer used by each TCP socket. The default value is the system page size. (On Linux 2.4, the default value is 4 kB, lowered to PAGE_SIZE bytes in low-memory systems.) This value is used to ensure that in memory pressure mode, allocations below this size will still succeed. This is not used to bound the size of the receive buffer declared using SO_RCVBUF on a socket.

default

the default size of the receive buffer for a TCP socket. This value overwrites the initial default buffer size from the generic global net.core.rmem_default defined for all protocols. The default value is 87380 bytes. (On Linux 2.4, this will be lowered to 43689 in low-memory systems.) If larger receive buffer sizes are desired, this value should be increased (to affect all sockets). To employ large TCP windows, the net.ipv4.tcp_window_scaling must be enabled (default).

max

the maximum size of the receive buffer used by each TCP socket. This value does not override the global net.core.rmem_max. This is not used to limit the size of the receive buffer declared using SO_RCVBUF on a socket. The default value is calculated using the formula

max(87380, min(4 MB, tcp_mem[1]*PAGE_SIZE/128))

(On Linux 2.4, the default is 87380*2 bytes, lowered to 87380 in low-memory systems).

tcp_sack (Boolean; default: enabled; since Linux 2.2)

Enable RFC 2018 TCP Selective Acknowledgements.

tcp_slow_start_after_idle (Boolean; default: enabled; since Linux 2.6.18)

If enabled, provide RFC 2861 behavior and time out the congestion window after an idle period. An idle period is defined as the current RTO (retransmission timeout). If disabled, the congestion window will not be timed out after an idle period.

tcp_stdurg (Boolean; default: disabled; since Linux 2.2)

If this option is enabled, then use the RFC 1122 interpretation of the TCP urgent-pointer field. According to this interpretation, the urgent pointer points to the last byte of urgent data. If this option is disabled, then use the BSD-compatible interpretation of the urgent pointer: the urgent pointer points to the first byte after the urgent data. Enabling this option may lead to interoperability problems.

tcp_syn_retries (integer; default: 6; since Linux 2.2)

The maximum number of times initial SYNs for an active TCP connection attempt will be retransmitted. This value should not be higher than 255. The default value is 6, which corresponds to retrying for up to approximately 127 seconds. Before Linux 3.7, the default value was 5, which (in conjunction with calculation based on other kernel parameters) corresponded to approximately 180 seconds.

tcp_synack_retries (integer; default: 5; since Linux 2.2)

The maximum number of times a SYN/ACK segment for a passive TCP connection will be retransmitted. This number should not be higher than 255.

tcp_syncookies (integer; default: 1; since Linux 2.2)

Enable TCP syncookies. The kernel must be compiled with CONFIG_SYN_COOKIES. The syncookies feature attempts to protect a socket from a SYN flood attack. This should be used as a last resort, if at all. This is a violation of the TCP protocol, and conflicts with other areas of TCP such as TCP extensions. It can cause problems for clients and relays. It is not recommended as a tuning mechanism for heavily loaded servers to help with overloaded or misconfigured conditions. For recommended alternatives see tcp_max_syn_backlog, tcp_synack_retries, and tcp_abort_on_overflow. Set to one of the following values:

0

Disable TCP syncookies.

1

Send out syncookies when the syn backlog queue of a socket overflows.

2

(since Linux 3.12) Send out syncookies unconditionally. This can be useful for network testing.

tcp_timestamps (integer; default: 1; since Linux 2.2)

Set to one of the following values to enable or disable RFC 1323 TCP timestamps:

0

Disable timestamps.

1

Enable timestamps as defined in RFC1323 and use random offset for each connection rather than only using the current time.

2

As for the value 1, but without random offsets. Setting tcp_timestamps to this value is meaningful since Linux 4.10.

tcp_tso_win_divisor (integer; default: 3; since Linux 2.6.9)

This parameter controls what percentage of the congestion window can be consumed by a single TCP Segmentation Offload (TSO) frame. The setting of this parameter is a tradeoff between burstiness and building larger TSO frames.

tcp_tw_recycle (Boolean; default: disabled; Linux 2.4 to 4.11)

Enable fast recycling of TIME_WAIT sockets. Enabling this option is not recommended as the remote IP may not use monotonically increasing timestamps (devices behind NAT, devices with per-connection timestamp offsets). See RFC 1323 (PAWS) and RFC 6191.

tcp_tw_reuse (Boolean; default: disabled; since Linux 2.4.19/2.6)

Allow to reuse TIME_WAIT sockets for new connections when it is safe from protocol viewpoint. It should not be changed without advice/request of technical experts.

tcp_vegas_cong_avoid (Boolean; default: disabled; Linux 2.2 to 2.6.13)

Enable TCP Vegas congestion avoidance algorithm. TCP Vegas is a sender-side-only change to TCP that anticipates the onset of congestion by estimating the bandwidth. TCP Vegas adjusts the sending rate by modifying the congestion window. TCP Vegas should provide less packet loss, but it is not as aggressive as TCP Reno.

tcp_westwood (Boolean; default: disabled; Linux 2.4.26/2.6.3 to 2.6.13)

Enable TCP Westwood+ congestion control algorithm. TCP Westwood+ is a sender-side-only modification of the TCP Reno protocol stack that optimizes the performance of TCP congestion control. It is based on end-to-end bandwidth estimation to set congestion window and slow start threshold after a congestion episode. Using this estimation, TCP Westwood+ adaptively sets a slow start threshold and a congestion window which takes into account the bandwidth used at the time congestion is experienced. TCP Westwood+ significantly increases fairness with respect to TCP Reno in wired networks and throughput over wireless links.

tcp_window_scaling (Boolean; default: enabled; since Linux 2.2)

Enable RFC 1323 TCP window scaling. This feature allows the use of a large window (> 64 kB) on a TCP connection, should the other end support it. Normally, the 16 bit window length field in the TCP header limits the window size to less than 64 kB. If larger windows are desired, applications can increase the size of their socket buffers and the window scaling option will be employed. If tcp_window_scaling is disabled, TCP will not negotiate the use of window scaling with the other end during connection setup.

tcp_wmem (since Linux 2.4)

This is a vector of 3 integers: [min, default, max]. These parameters are used by TCP to regulate send buffer sizes. TCP dynamically adjusts the size of the send buffer from the default values listed below, in the range of these values, depending on memory available.

min

Minimum size of the send buffer used by each TCP socket. The default value is the system page size. (On Linux 2.4, the default value is 4 kB.) This value is used to ensure that in memory pressure mode, allocations below this size will still succeed. This is not used to bound the size of the send buffer declared using SO_SNDBUF on a socket.

default

The default size of the send buffer for a TCP socket. This value overwrites the initial default buffer size from the generic global /proc/sys/net/core/wmem_default defined for all protocols. The default value is 16 kB. If larger send buffer sizes are desired, this value should be increased (to affect all sockets). To employ large TCP windows, the /proc/sys/net/ipv4/tcp_window_scaling must be set to a nonzero value (default).

max

The maximum size of the send buffer used by each TCP socket. This value does not override the value in /proc/sys/net/core/wmem_max. This is not used to limit the size of the send buffer declared using SO_SNDBUF on a socket. The default value is calculated using the formula

max(65536, min(4 MB, tcp_mem[1]*PAGE_SIZE/128))

(On Linux 2.4, the default value is 128 kB, lowered 64 kB depending on low-memory systems.)

tcp_workaround_signed_windows (Boolean; default: disabled; since Linux 2.6.26)

If enabled, assume that no receipt of a window-scaling option means that the remote TCP is broken and treats the window as a signed quantity. If disabled, assume that the remote TCP is not broken even if we do not receive a window scaling option from it.

### Socket options
To set or get a TCP socket option, call getsockopt(2) to read or setsockopt(2) to write the option with the option level argument set to IPPROTO_TCP. Unless otherwise noted, optval is a pointer to an int. In addition, most IPPROTO_IP socket options are valid on TCP sockets. For more information see ip(7).

Following is a list of TCP-specific socket options. For details of some other socket options that are also applicable for TCP sockets, see socket(7).

TCP_CONGESTION (since Linux 2.6.13)

The argument for this option is a string. This option allows the caller to set the TCP congestion control algorithm to be used, on a per-socket basis. Unprivileged processes are restricted to choosing one of the algorithms in tcp_allowed_congestion_control (described above). Privileged processes (CAP_NET_ADMIN) can choose from any of the available congestion-control algorithms (see the description of tcp_available_congestion_control above).

TCP_CORK (since Linux 2.2)

If set, don't send out partial frames. All queued partial frames are sent when the option is cleared again. This is useful for prepending headers before calling sendfile(2), or for throughput optimization. As currently implemented, there is a 200 millisecond ceiling on the time for which output is corked by TCP_CORK. If this ceiling is reached, then queued data is automatically transmitted. This option can be combined with TCP_NODELAY only since Linux 2.5.71. This option should not be used in code intended to be portable.

TCP_DEFER_ACCEPT (since Linux 2.4)

Allow a listener to be awakened only when data arrives on the socket. Takes an integer value (seconds), this can bound the maximum number of attempts TCP will make to complete the connection. This option should not be used in code intended to be portable.

TCP_INFO (since Linux 2.4)

Used to collect information about this socket. The kernel returns a struct tcp_info as defined in the file /usr/include/linux/tcp.h. This option should not be used in code intended to be portable.

TCP_KEEPCNT (since Linux 2.4)

The maximum number of keepalive probes TCP should send before dropping the connection. This option should not be used in code intended to be portable.

TCP_KEEPIDLE (since Linux 2.4)

The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes, if the socket option SO_KEEPALIVE has been set on this socket. This option should not be used in code intended to be portable.

TCP_KEEPINTVL (since Linux 2.4)

The time (in seconds) between individual keepalive probes. This option should not be used in code intended to be portable.

TCP_LINGER2 (since Linux 2.4)

The lifetime of orphaned FIN_WAIT2 state sockets. This option can be used to override the system-wide setting in the file /proc/sys/net/ipv4/tcp_fin_timeout for this socket. This is not to be confused with the socket(7) level option SO_LINGER. This option should not be used in code intended to be portable.

TCP_MAXSEG

The maximum segment size for outgoing TCP packets. In Linux 2.2 and earlier, and in Linux 2.6.28 and later, if this option is set before connection establishment, it also changes the MSS value announced to the other end in the initial packet. Values greater than the (eventual) interface MTU have no effect. TCP will also impose its minimum and maximum bounds over the value provided.

TCP_NODELAY

If set, disable the Nagle algorithm. This means that segments are always sent as soon as possible, even if there is only a small amount of data. When not set, data is buffered until there is a sufficient amount to send out, thereby avoiding the frequent sending of small packets, which results in poor utilization of the network. This option is overridden by TCP_CORK; however, setting this option forces an explicit flush of pending output, even if TCP_CORK is currently set.

TCP_QUICKACK (since Linux 2.4.4)

Enable quickack mode if set or disable quickack mode if cleared. In quickack mode, acks are sent immediately, rather than delayed if needed in accordance to normal TCP operation. This flag is not permanent, it only enables a switch to or from quickack mode. Subsequent operation of the TCP protocol will once again enter/leave quickack mode depending on internal protocol processing and factors such as delayed ack timeouts occurring and data transfer. This option should not be used in code intended to be portable.

TCP_SYNCNT (since Linux 2.4)

Set the number of SYN retransmits that TCP should send before aborting the attempt to connect. It cannot exceed 255. This option should not be used in code intended to be portable.

TCP_USER_TIMEOUT (since Linux 2.6.37)

This option takes an unsigned int as an argument. When the value is greater than 0, it specifies the maximum amount of time in milliseconds that transmitted data may remain unacknowledged, or bufferred data may remain untransmitted (due to zero window size) before TCP will forcibly close the corresponding connection and return ETIMEDOUT to the application. If the option value is specified as 0, TCP will use the system default.

Increasing user timeouts allows a TCP connection to survive extended periods without end-to-end connectivity. Decreasing user timeouts allows applications to "fail fast", if so desired. Otherwise, failure may take up to 20 minutes with the current system defaults in a normal WAN environment.

This option can be set during any state of a TCP connection, but is effective only during the synchronized states of a connection (ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, and LAST-ACK). Moreover, when used with the TCP keepalive (SO_KEEPALIVE) option, TCP_USER_TIMEOUT will override keepalive to determine when to close a connection due to keepalive failure.

The option has no effect on when TCP retransmits a packet, nor when a keepalive probe is sent.

This option, like many others, will be inherited by the socket returned by accept(2), if it was set on the listening socket.

Further details on the user timeout feature can be found in RFC 793 and RFC 5482 ("TCP User Timeout Option").

TCP_WINDOW_CLAMP (since Linux 2.4)

Bound the size of the advertised window to this value. The kernel imposes a minimum size of SOCK_MIN_RCVBUF/2. This option should not be used in code intended to be portable.

### Sockets API
TCP provides limited support for out-of-band data, in the form of (a single byte of) urgent data. In Linux this means if the other end sends newer out-of-band data the older urgent data is inserted as normal data into the stream (even when SO_OOBINLINE is not set). This differs from BSD-based stacks.

Linux uses the BSD compatible interpretation of the urgent pointer field by default. This violates RFC 1122, but is required for interoperability with other stacks. It can be changed via /proc/sys/net/ipv4/tcp_stdurg.

It is possible to peek at out-of-band data using the recv(2) MSG_PEEK flag.

Since version 2.4, Linux supports the use of MSG_TRUNC in the flags argument of recv(2) (and recvmsg(2)). This flag causes the received bytes of data to be discarded, rather than passed back in a caller-supplied buffer. Since Linux 2.4.4, MSG_TRUNC also has this effect when used in conjunction with MSG_OOB to receive out-of-band data.

### Ioctls
The following ioctl(2) calls return information in value. The correct syntax is:

```
int value;
error = ioctl(tcp_socket, ioctl_type, &value);
```

ioctl_type is one of the following:

SIOCINQ

Returns the amount of queued unread data in the receive buffer. The socket must not be in LISTEN state, otherwise an error (EINVAL) is returned. SIOCINQ is defined in <linux/sockios.h>. Alternatively, you can use the synonymous FIONREAD, defined in <sys/ioctl.h>.

SIOCATMARK

Returns true (i.e., value is nonzero) if the inbound data stream is at the urgent mark.

If the SO_OOBINLINE socket option is set, and SIOCATMARK returns true, then the next read from the socket will return the urgent data. If the SO_OOBINLINE socket option is not set, and SIOCATMARK returns true, then the next read from the socket will return the bytes following the urgent data (to actually read the urgent data requires the recv(MSG_OOB) flag).

Note that a read never reads across the urgent mark. If an application is informed of the presence of urgent data via select(2) (using the exceptfds argument) or through delivery of a SIGURG signal, then it can advance up to the mark using a loop which repeatedly tests SIOCATMARK and performs a read (requesting any number of bytes) as long as SIOCATMARK returns false.

SIOCOUTQ

Returns the amount of unsent data in the socket send queue. The socket must not be in LISTEN state, otherwise an error (EINVAL) is returned. SIOCOUTQ is defined in <linux/sockios.h>. Alternatively, you can use the synonymous TIOCOUTQ, defined in <sys/ioctl.h>.

### Error handling
When a network error occurs, TCP tries to resend the packet. If it doesn't succeed after some time, either ETIMEDOUT or the last received error on this connection is reported.

Some applications require a quicker error notification. This can be enabled with the IPPROTO_IP level IP_RECVERR socket option. When this option is enabled, all incoming errors are immediately passed to the user program. Use this option with care — it makes TCP less tolerant to routing changes and other normal network conditions.

## ERRORS
EAFNOTSUPPORT

Passed socket address type in sin_family was not AF_INET.

EPIPE

The other end closed the socket unexpectedly or a read is executed on a shut down socket.

ETIMEDOUT

The other end didn't acknowledge retransmitted data after some time.

Any errors defined for ip(7) or the generic socket layer may also be returned for TCP.

## VERSIONS
Support for Explicit Congestion Notification, zero-copy sendfile(2), reordering support and some SACK extensions (DSACK) were introduced in 2.4. Support for forward acknowledgement (FACK), TIME_WAIT recycling, and per-connection keepalive socket options were introduced in 2.3.

## BUGS
Not all errors are documented.

IPv6 is not described.

## SEE ALSO
accept(2), bind(2), connect(2), getsockopt(2), listen(2), recvmsg(2), sendfile(2), sendmsg(2), socket(2), ip(7), socket(7)

The kernel source file Documentation/networking/ip-sysctl.txt.

RFC 793 for the TCP specification.

RFC 1122 for the TCP requirements and a description of the Nagle algorithm.

RFC 1323 for TCP timestamp and window scaling options.

RFC 1337 for a description of TIME_WAIT assassination hazards.

RFC 3168 for a description of Explicit Congestion Notification.

RFC 2581 for TCP congestion control algorithms.

RFC 2018 and RFC 2883 for SACK and extensions to SACK.


termio

title: termio(7)

summary: System V terminal driver interface

text:
# termio(7)

## NAME
termio - System V terminal driver interface

## DESCRIPTION
termio is the name of the old System V terminal driver interface. This interface defined a termio structure used to store terminal settings, and a range of ioctl(2) operations to get and set terminal attributes.

The termio interface is now obsolete: POSIX.1-1990 standardized a modified version of this interface, under the name termios. The POSIX.1 data structure differs slightly from the System V version, and POSIX.1 defined a suite of functions to replace the various ioctl(2) operations that existed in System V. (This was done because ioctl(2) was unstandardized, and its variadic third argument does not allow argument type checking.)

If you're looking for a page called "termio", then you can probably find most of the information that you seek in either termios(3) or ioctl_tty(2).

## SEE ALSO
reset(1), setterm(1), stty(1), ioctl_tty(2), termios(3), tty(4)


thread-keyring

title: thread-keyring(7)

summary: per-thread keyring

text:
# thread-keyring(7)

## NAME
thread-keyring - per-thread keyring

## DESCRIPTION
The thread keyring is a keyring used to anchor keys on behalf of a process. It is created only when a thread requests it. The thread keyring has the name (description) _tid.

A special serial number value, KEY_SPEC_THREAD_KEYRING, is defined that can be used in lieu of the actual serial number of the calling thread's thread keyring.

From the keyctl(1) utility, '@t' can be used instead of a numeric key ID in much the same way, but as keyctl(1) is a program run after forking, this is of no utility.

Thread keyrings are not inherited across clone(2) and fork(2) and are cleared by execve(2). A thread keyring is destroyed when the thread that refers to it terminates.

Initially, a thread does not have a thread keyring. If a thread doesn't have a thread keyring when it is accessed, then it will be created if it is to be modified; otherwise the operation fails with the error ENOKEY.

## SEE ALSO
keyctl(1), keyctl(3), keyrings(7), persistent-keyring(7), process-keyring(7), session-keyring(7), user-keyring(7), user-session-keyring(7)


time

title: time(7)

summary: overview of time and timers

text:
# time(7)

## NAME
time - overview of time and timers

## DESCRIPTION

### Real time and process time
Real time is defined as time measured from some fixed point, either from a standard point in the past (see the description of the Epoch and calendar time below), or from some point (e.g., the start) in the life of a process (elapsed time).

Process time is defined as the amount of CPU time used by a process. This is sometimes divided into user and system components. User CPU time is the time spent executing code in user mode. System CPU time is the time spent by the kernel executing in system mode on behalf of the process (e.g., executing system calls). The time(1) command can be used to determine the amount of CPU time consumed during the execution of a program. A program can determine the amount of CPU time it has consumed using times(2), getrusage(2), or clock(3).

### The hardware clock
Most computers have a (battery-powered) hardware clock which the kernel reads at boot time in order to initialize the software clock. For further details, see rtc(4) and hwclock(8).

### The software clock, HZ, and jiffies
The accuracy of various system calls that set timeouts, (e.g., select(2), sigtimedwait(2)) and measure CPU time (e.g., getrusage(2)) is limited by the resolution of the software clock, a clock maintained by the kernel which measures time in jiffies. The size of a jiffy is determined by the value of the kernel constant HZ.

The value of HZ varies across kernel versions and hardware platforms. On i386 the situation is as follows: on kernels up to and including 2.4.x, HZ was 100, giving a jiffy value of 0.01 seconds; starting with 2.6.0, HZ was raised to 1000, giving a jiffy of 0.001 seconds. Since kernel 2.6.13, the HZ value is a kernel configuration parameter and can be 100, 250 (the default) or 1000, yielding a jiffies value of, respectively, 0.01, 0.004, or 0.001 seconds. Since kernel 2.6.20, a further frequency is available: 300, a number that divides evenly for the common video frame rates (PAL, 25 HZ; NTSC, 30 HZ).

The times(2) system call is a special case. It reports times with a granularity defined by the kernel constant USER_HZ. User-space applications can determine the value of this constant using sysconf(_SC_CLK_TCK).

### System and process clocks; time namespaces
The kernel supports a range of clocks that measure various kinds of elapsed and virtual (i.e., consumed CPU) time. These clocks are described in clock_gettime(2). A few of the clocks are settable using clock_settime(2). The values of certain clocks are virtualized by time namespaces; see time_namespaces(7).

### High-resolution timers
Before Linux 2.6.21, the accuracy of timer and sleep system calls (see below) was also limited by the size of the jiffy.

Since Linux 2.6.21, Linux supports high-resolution timers (HRTs), optionally configurable via CONFIG_HIGH_RES_TIMERS. On a system that supports HRTs, the accuracy of sleep and timer system calls is no longer constrained by the jiffy, but instead can be as accurate as the hardware allows (microsecond accuracy is typical of modern hardware). You can determine whether high-resolution timers are supported by checking the resolution returned by a call to clock_getres(2) or looking at the "resolution" entries in /proc/timer_list.

HRTs are not supported on all hardware architectures. (Support is provided on x86, arm, and powerpc, among others.)

### The Epoch
UNIX systems represent time in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).

A program can determine the calendar time via the clock_gettime(2) CLOCK_REALTIME clock, which returns time (in seconds and nanoseconds) that have elapsed since the Epoch; time(2) provides similar information, but only with accuracy to the nearest second. The system time can be changed using clock_settime(2).

### Broken-down time
Certain library functions use a structure of type tm to represent broken-down time, which stores time value separated out into distinct components (year, month, day, hour, minute, second, etc.). This structure is described in ctime(3), which also describes functions that convert between calendar time and broken-down time. Functions for converting between broken-down time and printable string representations of the time are described in ctime(3), strftime(3), and strptime(3).

### Sleeping and setting timers
Various system calls and functions allow a program to sleep (suspend execution) for a specified period of time; see nanosleep(2), clock_nanosleep(2), and sleep(3).

Various system calls allow a process to set a timer that expires at some point in the future, and optionally at repeated intervals; see alarm(2), getitimer(2), timerfd_create(2), and timer_create(2).

### Timer slack
Since Linux 2.6.28, it is possible to control the "timer slack" value for a thread. The timer slack is the length of time by which the kernel may delay the wake-up of certain system calls that block with a timeout. Permitting this delay allows the kernel to coalesce wake-up events, thus possibly reducing the number of system wake-ups and saving power. For more details, see the description of PR_SET_TIMERSLACK in prctl(2).

## SEE ALSO
date(1), time(1), timeout(1), adjtimex(2), alarm(2), clock_gettime(2), clock_nanosleep(2), getitimer(2), getrlimit(2), getrusage(2), gettimeofday(2), nanosleep(2), stat(2), time(2), timer_create(2), timerfd_create(2), times(2), utime(2), adjtime(3), clock(3), clock_getcpuclockid(3), ctime(3), ntp_adjtime(3), ntp_gettime(3), pthread_getcpuclockid(3), sleep(3), strftime(3), strptime(3), timeradd(3), usleep(3), rtc(4), time_namespaces(7), hwclock(8)