In theCandC++programming languages,unistd.his the name of theheader filethat provides access to thePOSIXoperating systemAPI.[1]It is defined by the POSIX.1 standard, the base of theSingle Unix Specification,and should therefore be available in any POSIX-compliant operating system andcompiler.For instance, this includesUnixandUnix-likeoperating systems, such asGNU variants,distributions ofLinuxandBSD,andmacOS,and compilers such asGCCandLLVM.

On Unix-like systems, the interface defined byunistd.his typically made up largely ofsystem call wrapper functionssuch asfork,pipeandI/Oprimitives (read,write,close,etc.).

Unix compatibility layers such asCygwinandMinGWalso 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/includethat 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 (likestddef.h) which provide the typesize_tand 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

edit
Function Description
crypt password and dataencryption
encrypt encrypt 64-byte messages
gethostid get the unique identifier of the current host
gethostname gethostname
getopt parsecommand-line options
swab swap adjacent bytes
sysconf get configuration at run time
Signals alarm schedule an alarmsignal
pause wait for signal
Filesystem access
faccessat
faccessat2
check user'spermissionsfor a file or whether it exists
chdir
fchdir
changeworking directory
chown
fchown
lchown
fchownat
change owner and group of a file
close close afile 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 aterminal
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 callingprocess
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

References

edit
  1. ^"unistd.h(0P)".POSIX Programmer's Manual.IEEE/The Open Group. 2017.Retrieved9 February2024.
edit