HOME

TheInfoList



OR:

is a
system call In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
and
application programming interface An application programming interface (API) is a connection between computers or between computer programs. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standard that des ...
(API) in
Unix-like A Unix-like (sometimes referred to as UN*X, *nix or *NIX) 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 Uni ...
and
POSIX The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
-compliant operating systems for examining the status of
file descriptor In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket. File descriptors typically h ...
s of open input/output channels. The select system call is similar to the ' facility introduced in UNIX System V and later operating systems. However, with the c10k problem, both select and poll have been superseded by the likes of
kqueue Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 in July 2000, also supported in NetBSD, OpenBSD, DragonFly BSD, and macOS. Kqueue was originally authored in 2000 by Jonathan Lemon, then involved with the FreeBSD Core T ...
,
epoll epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5.45 of the Linux kernel. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them. It is ...
, /dev/poll and I/O completion ports. One common use of select outside of its stated use of waiting on filehandles is to implement a portable sub-second
sleep Sleep is a state of reduced mental and physical activity in which consciousness is altered and certain Sensory nervous system, sensory activity is inhibited. During sleep, there is a marked decrease in muscle activity and interactions with th ...
. This can be achieved by passing NULL for all three fd_set arguments, and the duration of the desired sleep as the timeout argument. In the
C programming language C (''pronounced'' '' – like the letter c'') is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of ...
, the select system call is declared in the header file sys/select.h or
unistd.h In the C programming language, C and C++ programming languages, unistd.h is the name of the header file that provides access to the POSIX operating system application programming interface, API. It is defined by the POSIX.1 standard, the base ...
, and has the following syntax: int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout); fd_set type arguments may be manipulated with four utility macros: , and . Select returns the total number of bits set in and , or zero if the timeout expired, and -1 on error. The sets of file descriptor used in select are finite in size, depending on the operating system. The newer system call ' provides a more flexible solution.


Example

#include #include #include #include #include #include #include #include #include #include #include #include #define PORT "9421" /* function prototypes */ void die(const char*); int main(int argc, char **argv) void die(const char *msg)


See also

*
Berkeley sockets A Berkeley ( BSD) socket is an application programming interface (API) for Internet domain sockets and Unix domain sockets, used for inter-process communication (IPC). It is commonly implemented as a library of linkable modules. It originated wi ...
* Polling *
epoll epoll is a Linux kernel system call for a scalable I/O event notification mechanism, first introduced in version 2.5.45 of the Linux kernel. Its function is to monitor multiple file descriptors to see whether I/O is possible on any of them. It is ...
*
kqueue Kqueue is a scalable event notification interface introduced in FreeBSD 4.1 in July 2000, also supported in NetBSD, OpenBSD, DragonFly BSD, and macOS. Kqueue was originally authored in 2000 by Jonathan Lemon, then involved with the FreeBSD Core T ...
*
Input/output completion port Input/output completion port (IOCP) is an API for performing multiple simultaneous asynchronous input/output operations in Windows NT versions 3.5 and later, AIX and on Solaris 10 and later. An input/output completion port object is created and ...
(IOCP)


References


External links

* * {{URL, http://mdoc.su/-/select.2, man-pages for select(2) in FreeBSD, NetBSD, OpenBSD and DragonFly BSD C POSIX library Events (computing) System calls Articles with example C code