unistd.h
Overview
Related Modules:
Description:
Provides functions and data structures related to process operations.
For example, you can use the functions to create and copy a process, and obtain a process ID.
Since:
1.0
Version:
1.0
Summary
Macros
| Macro Name and Value | Description |
|---|---|
| STDIN_FILENO 0 | Descriptor ID of the standard input file. |
| STDOUT_FILENO 1 | Descriptor ID of the standard output file. |
| STDERR_FILENO 2 | Descriptor ID of the standard error file. |
| SEEK_SET 0 | Relocation starts from the file header. |
| SEEK_CUR 1 | Relocation starts from the position of the currently accessed file. |
| SEEK_END 2 | Relocation starts from the end of the file. |
| NULL ((void*)0) | NULL. |
| F_OK 0 | Existing file. |
| R_OK 4 | Readable file. |
| W_OK 2 | Writable file. |
| X_OK 1 | Executable file. |
Functions
| Function Name | Description |
|---|---|
| pipe (int pipefd[2]) | int Creates an anonymous pipe. |
| close (int fd) | int Closes a file with a specified file descriptor. |
| dup (int oldfd) | int Copies a specified file descriptor. |
| dup2 (int oldfd, int newfd) | int Copies the descriptor of the target file to a specified descriptor. |
| lseek (int fd, off_t offset, int whence) | off_t Sets the offset of the pointer to the file. |
| fsync (int fd) | int Synchronizes a file associated with a specified file descriptor to the storage device. |
| read (int fd, void buf, size_t size) | ssize_t Reads the file contents and saves them in a specified buffer location. |
| write (int fd, const void buf, size_t size) | ssize_t Writes the specified content to the file. |
| pread (int fd, void buf, size_t count, off_t offset) | ssize_t Reads data whose offset is offset and length is count from fd to the buffer. |
| pwrite (int fd, const void buf, size_t count, off_t offset) | ssize_t Writes data from the buffer to fd whose offset is offset and length is count. |
| unlink (const char path) | int Deletes a specified file. |
| unlinkat (int fd, const char path, int flag) | int Deletes a specified file. |
| rmdir (const char path) | int Deletes a directory. |
| truncate (const char path, off_t length) | int Truncates a file to a specified size based on the file path. |
| ftruncate (int fd, off_t length) | int Truncates a file to a specified length. |
| access (const char path, int mode) | int Checks whether a file has the corresponding permission. |
| chdir (const char path) | int Switches the current working directory to a specified directory. |
| getcwd (char buf, size_t size) | char Obtains the current working directory. |
| alarm (unsigned int seconds) | unsigned int Arranges a signal to be sent to the current process after the number of seconds specified by seconds. |
| sleep (unsigned seconds) | unsigned Sleeps for a period of time. |
| pause (void) | int Waits for signal. |
| fork (void) | pid_t Creates a new process that inherits from the user-mode data of its parent process. |
| execve (const char path, char const arg[], char const envp[]) | int Executes a specified user program file in ELF format. |
| execv (const char path, char const arg[]) | int Executes a specified user program file in ELF format. |
| execle (const char path, const char arg,…) | int Executes a specified user program file in ELF format. |
| execl (const char path, const char arg,…) | int Executes a specified user program file in ELF format. |
| execvp (const char path, char const arg[]) | int Executes a specified user program file in ELF format. |
| execlp (const char path, const char arg,…) | int Executes a specified user program file in ELF format. |
| _exit (int status) | _Noreturn void Exits the process immediately and closes all opened file descriptors in the process. |
| swab (const void from, void to, ssize_t n) | void Swaps bytes. |
| getpid (void) | pid_t Obtains the process ID. |
| getppid (void) | pid_t Obtains the parent process ID. |
| getpgrp (void) | pid_t Obtains the ID of the process group of the calling process. |
| getpgid (pid_t pid) | pid_t Obtains the ID of the process group whose process ID is specified by pid. |
| setpgid (pid_t pid, pid_t pgid) | int Sets the ID of the process group whose process ID is specified by pid. |
| getopt (int argc, char const argv[], const char optstring) | int Parses command-line arguments based on the specified option. |
| getuid (void) | uid_t Obtains the real user ID (UID) of the calling process. |
| geteuid (void) | uid_t Obtains the effective user ID (UID) of the calling process. |
| getgid (void) | gid_t Obtains the real group ID (GID) of the calling process. |
| getegid (void) | gid_t Obtains the effective group ID (GID) of the calling process. |
| getgroups (int size, gid_t list[]) | int Obtains a list of supplementary user group IDs specific to the calling process. |
| setuid (uid_t uid) | int Sets the real user ID for the calling process. |
| seteuid (uid_t euid) | int Sets the effective user ID of the calling process. |
| setgid (gid_t gid) | int Sets the user group ID of the calling process. |
| setegid (gid_t egid) | int Sets the effective user group ID of the calling process. |
| pathconf (const char path, int name) | long Obtains the configuration value of a file. |
| setreuid (uid_t ruid, uid_t euid) | int Sets the real and effective user IDs of the calling process. |
| setregid (gid_t rgid, gid_t egid) | int Sets the real and effective user group IDs of the calling process. |
| setpgrp (void) | pid_t Sets the process group ID of the calling process. |
| usleep (unsigned useconds) | int Sleeps for several microseconds. |
| ualarm (unsigned value, unsigned interval) | unsigned Sets a microsecond-level timer. |
| setgroups (size_t size, const gid_t list) | int Sets the supplementary user group list of the calling process. |
| setresuid (uid_t ruid, uid_t euid, uid_t suid) | int Sets the real, effective, and saved user IDs of the calling process. |
| setresgid (gid_t rgid, gid_t egid, gid_t sgid) | int Sets the real, effective, and saved group IDs of the calling process. |
| getresuid (uid_t ruid, uid_t euid, uid_t suid) | int Obtains the real, effective, and saved user IDs of the calling process. |
| getresgid (gid_t rgid, gid_t egid, gid_t sgid) | int Obtains the real, effective, and saved user group IDs of the calling process. |
| get_current_dir_name (void) | char Obtains the name of the current working directory. |
| sbrk (intptr_t increment) | void Adjusts the heap size of a process. |
| getpagesize (void) | int Obtains the memory page size. |
| chown (const char pathname, uid_t owner, gid_t group) | int Changes the user and group ownership of a file. |
