Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


stdin(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |STANDARDS |HISTORY |NOTES |SEE ALSO |COLOPHON

stdin(3)                 Library Functions Manualstdin(3)

NAME        top

       stdin, stdout, stderr - standard I/O streams

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <stdio.h>extern FILE  *stdin;extern FILE  *stdout;extern FILE  *stderr;

DESCRIPTION        top

       Under normal circumstances every UNIX program has three streams       opened for it when it starts up, one for input, one for output,       and one for printing diagnostic or error messages.  These are       typically attached to the user's terminal (seetty(4)) but might       instead refer to files or other devices, depending on what the       parent process chose to set up.  (See also the "Redirection"       section ofsh(1).)       The input stream is referred to as "standard input"; the output       stream is referred to as "standard output"; and the error stream       is referred to as "standard error".  These terms are abbreviated       to form the symbols used to refer to these files, namelystdin,stdout, andstderr.       Each of these symbols is astdio(3) macro of type pointer toFILE,       and can be used with functions likefprintf(3) orfread(3).       SinceFILEs are a buffering wrapper around UNIX file descriptors,       the same underlying files may also be accessed using the raw UNIX       file interface, that is, the functions likeread(2) andlseek(2).       On program startup, the integer file descriptors associated with       the streamsstdin,stdout, andstderr are 0, 1, and 2,       respectively.  The preprocessor symbolsSTDIN_FILENO,STDOUT_FILENO, andSTDERR_FILENOare defined with these values in<unistd.h>.  (Applyingfreopen(3) to one of these streams can       change the file descriptor number associated with the stream.)       Note that mixing use ofFILEs and raw file descriptors can produce       unexpected results and should generally be avoided.  (For the       masochistic among you: POSIX.1, section 8.2.3, describes in detail       how this interaction is supposed to work.)  A general rule is that       file descriptors are handled in the kernel, while stdio is just a       library.  This means for example, that after anexec(3), the child       inherits all open file descriptors, but all old streams have       become inaccessible.       Since the symbolsstdin,stdout, andstderr are specified to be       macros, assigning to them is nonportable.  The standard streams       can be made to refer to different files with help of the library       functionfreopen(3), specially introduced to make it possible to       reassignstdin,stdout, andstderr.  The standard streams are       closed by a call toexit(3) and by normal program termination.

STANDARDS        top

       C11, POSIX.1-2008.       The standards also stipulate that these three streams shall be       open at program startup.

HISTORY        top

       C89, POSIX.1-2001.

NOTES        top

       The streamstderr is unbuffered.  The streamstdout is line-       buffered when it points to a terminal.  Partial lines will not       appear untilfflush(3) orexit(3) is called, or a newline is       printed.  This can produce unexpected results, especially with       debugging output.  The buffering mode of the standard streams (or       any other stream) can be changed using thesetbuf(3) orsetvbuf(3)       call.  Note that in casestdin is associated with a terminal,       there may also be input buffering in the terminal driver, entirely       unrelated to stdio buffering.  (Indeed, normally terminal input is       line buffered in the kernel.)  This kernel input handling can be       modified using calls liketcsetattr(3); see alsostty(1), andtermios(3).

SEE ALSO        top

csh(1),sh(1),open(2),fopen(3),stdio(3)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-06stdin(3)

Pages that refer to this page:intro(1)FILE(3type)stdio(3)pam_exec(8)


Copyright and license for this manual page


HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp