HOME

TheInfoList



OR:

is a
system call In computing, a system call (commonly abbreviated to 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, acc ...
and application programming interface (API) in
Unix-like A Unix-like (sometimes referred to as UN*X 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 Unix-li ...
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 both the system- and user-level application programming inte ...
-compliant operating systems for examining the status of file descriptors 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, /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 sedentary state of mind and body. It is characterized by altered consciousness, relatively inhibited Perception, sensory activity, reduced muscle activity and reduced interactions with surroundings. It is distinguished from wakefuln ...
. 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 ''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language, as well as ...
, 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 of ...
, 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 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.2BS ...
*
Polling Poll, polled, or polling may refer to: Figurative head counts * Poll, a formal election ** Election verification exit poll, a survey taken to verify election counts ** Polling, voting to make decisions or determine opinions ** Polling places o ...
* epoll *
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