Unistd.h

Last updated

In the C and C++ programming languages, unistd.h is the name of the header file that provides access to the POSIX operating system API. [1] It is defined by the POSIX.1 standard, the base of the Single Unix Specification, and should therefore be available in any POSIX-compliant operating system and compiler. For instance, this includes Unix and Unix-like operating systems, such as GNU variants, distributions of Linux and BSD, and macOS, and compilers such as GCC and LLVM.

Contents

On Unix-like systems, the interface defined by unistd.h is typically made up largely of system call wrapper functions such as fork , pipe and I/O primitives (read, write, close, etc.).

Unix compatibility layers such as Cygwin and MinGW also provide their own versions of unistd.h. In fact, those systems provide it along with the translation libraries that implement its functions in terms of win32 functions. E.g. In Cygwin, a header file can be found in /usr/include that sub-includes a file of the same name in /usr/include/sys. Not everything is defined in there but some definitions are done by references to the GNU C standard library headers (like stddef.h) which provide the type size_t and many more. Thus, unistd.h is only a generically defined adaptive layer that might be based upon already existing system and compiler specific definitions. This has the general advantage of not having a possibly concurrent set of header file defined, but one that is built upon the same root which, for this reason, will raise much fewer concerns in combined usage cases.

Overview of functions

FunctionDescription
crypt password and data encryption
encrypt encrypt 64-byte messages
gethostid get the unique identifier of the current host
gethostname get hostname
getopt parse command-line options
swab swap adjacent bytes
sysconf get configuration at run time
Signals alarm schedule an alarm signal
pause wait for signal
Filesystem access
faccessat
faccessat2
check user's permissions for a file or whether it exists
chdir
fchdir
change working directory
chown
fchown
lchown
fchownat
change owner and group of a file
close close a file descriptor
dup
dup2
duplicate a file descriptor
fsync
fdatasync
synchronize a file's in-core state with storage device
fpathconf
pathconf
get configuration values for files
ftruncate
truncate
truncate a file to a specified length
getcwd
getwd
get_current_dir_name
get current working directory
isatty test whether a file descriptor refers to a terminal
link
linkat
make a new name for a file
lockf apply, test or remove a POSIX lock on an open file
lseek reposition read/write file offset
pipe
pipe2
create pipe
pread
pwrite
read from or write to a file descriptor at a given offset
read read from a file descriptor
readlink
readlinkat
read value of a symbolic link
rmdir delete a directory
symlink
symlinkat
make a new name for a file
sync
syncfs
commit filesystem caches to disk
ttyname
ttyname_r
return name of a terminal
unlink
unlinkat
delete a name and possibly the file it refers to
write write to a file descriptor
Process _exit terminate the calling process
execl
execlp
execle
execv
execvp
execvpe
execute a file
fexecve execute program specified via file descriptor
fork create a new process
setpgid
getpgid
setpgrp
getpgrp
set/get process group
getpid
getppid
get process identification
getsid get session ID
nice change process priority
setsid creates a session and sets the process group ID
sleep sleep for a specified number of seconds
tcgetpgrp
tcsetpgrp
get and set terminal foreground process group
User/Group getgid
getegid
get group identity
getuid
geteuid
get user identity
getgroups get list of supplementary group IDs
getlogin
getlogin_r
get username
seteuid
setegid
set effective user or group ID
setgid set group identity
setreuid
setregid
set real and/or effective user or group ID
setuid set user identity

Related Research Articles

<span class="mw-page-title-main">Cygwin</span> Unix subsystem for Windows machines

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows.

The Portable Operating System Interface is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system and user-level application programming interfaces (APIs), along with command line shells and utility interfaces, for software compatibility (portability) with variants of Unix and other operating systems. POSIX is also a trademark of the IEEE. POSIX is intended to be used by both application and system developers.

The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, and user commands. The core specifications of the SUS known as Base Specifications are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO/IEC JTC 1/SC 22/WG 15 and The Open Group. If an operating system is submitted to The Open Group for certification, and passes conformance tests, then it is deemed to be compliant with a UNIX standard such as UNIX 98 or UNIX 03.

Berkeley sockets is an application programming interface (API) for Internet sockets and Unix domain sockets, used for inter-process communication (IPC). It is commonly implemented as a library of linkable modules. It originated with the 4.2BSD Unix operating system, which was released in 1983.

In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed to write data to sequential I/O devices with no file system of their own, such as devices that use magnetic tape. The archive data sets created by tar contain various file system parameters, such as name, timestamps, ownership, file-access permissions, and directory organization. POSIX abandoned tar in favor of pax, yet tar sees continued widespread use.

<span class="mw-page-title-main">GNU Autotools</span> Suite of programming tools

The GNU Autotools, also known as the GNU Build System, is a suite of programming tools designed to assist in making source code packages portable to many Unix-like systems.

In computer programming, standard streams are preconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console, but standard streams abstract this. When a command is executed via an interactive shell, the streams are typically connected to the text terminal on which the shell is running, but can be changed with redirection or a pipeline. More generally, a child process inherits the standard streams of its parent process.

The C preprocessor is the macro preprocessor for several computer programming languages, such as C, Objective-C, C++, and a variety of Fortran languages. The preprocessor provides inclusion of header files, macro expansions, conditional compilation, and line control.

The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>. The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s, and officially became part of the Unix operating system in Version 7.

The C standard library or libc is the standard library for the C programming language, as specified in the ISO C standard. Starting from the original ANSI C standard, it was developed at the same time as the C library POSIX specification, which is a superset of it. Since ANSI C was adopted by the International Organization for Standardization, the C standard library is also called the ISO C library.

MinGW, formerly mingw32, is a free and open source software development environment to create Microsoft Windows applications.

errno.h is a header file in the standard library of the C programming language. It defines macros for reporting and retrieving error conditions using the symbol errno.

The archiver, also known simply as ar, is a Unix utility that maintains groups of files as a single archive file. Today, ar is generally used only to create and update static library files that the link editor or linker uses and for generating .deb packages for the Debian family; it can be used to create archives for any purpose, but has been largely replaced by tar for purposes other than static libraries. An implementation of ar is included as one of the GNU Binutils.

In computing, POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a programming language, as well as a parallel execution model. It allows a program to control multiple different flows of work that overlap in time. Each flow of work is referred to as a thread, and creation and control over these flows is achieved by making calls to the POSIX Threads API. POSIX Threads is an API defined by the Institute of Electrical and Electronics Engineers (IEEE) standard POSIX.1c, Threads extensions .

<span class="mw-page-title-main">Linux kernel interfaces</span> An overview and comparison of the Linux kernal APIs and ABIs.

The Linux kernel provides multiple interfaces to user-space and kernel-mode code that are used for varying purposes and that have varying properties by design. There are two types of application programming interface (API) in the Linux kernel:

  1. the "kernel–user space" API; and
  2. the "kernel internal" API.

C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions. All functions use floating-point numbers in one manner or another. Different C standards provide different, albeit backwards-compatible, sets of functions. Most of these functions are also available in the C++ standard library, though in different headers.

<span class="mw-page-title-main">Unix-like</span> Operating system that behaves in a manner similar to a Unix system

A Unix-like operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Unix-like application is one that behaves like the corresponding Unix command or shell. Although there are general philosophies for Unix design, there is no technical standard defining the term, and opinions can differ about the degree to which a particular operating system or application is Unix-like.

<span class="mw-page-title-main">Unix</span> Family of computer operating systems

Unix is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, and others.

Getopt is a C library function used to parse command-line options of the Unix/POSIX style. It is a part of the POSIX specification, and is universal to Unix-like systems. It is also the name of a Unix program for parsing command line arguments in shell scripts.

Mingw-w64 is a free and open source software development environment to create (cross-compile) Microsoft Windows PE applications. It was forked in 2005–2010 from MinGW.

References

  1. "unistd.h(0P)". POSIX Programmer's Manual. IEEE/The Open Group. 2017. Retrieved 9 February 2024.