亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? library_14.html

?? Glibc的中文手冊
?? HTML
字號:
<!-- This HTML file has been created by texi2html 1.27
     from library.texinfo on 3 March 1994 -->

<TITLE>The GNU C Library - Pipes and FIFOs</TITLE>
<P>Go to the <A HREF="library_13.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html">previous</A>, <A HREF="library_15.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html">next</A> section.<P>
<H1><A NAME="SEC211" HREF="library_toc.html#SEC211" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC211">Pipes and FIFOs</A></H1>
<A NAME="IDX873"></A>
<P>
A <DFN>pipe</DFN> is a mechanism for interprocess communication; data written
to the pipe by one process can be read by another process.  The data is
handled in a first-in, first-out (FIFO) order.  The pipe has no name; it
is created for one use and both ends must be inherited from the single
process which created the pipe.
<A NAME="IDX874"></A>
<P>
A <DFN>FIFO special file</DFN> is similar to a pipe, but instead of being an
anonymous, temporary connection, a FIFO has a name or names like any
other file.  Processes open the FIFO by name in order to communicate
through it.
<P>
A pipe or FIFO has to be open at both ends simultaneously.  If you read
from a pipe or FIFO file that doesn't have any processes writing to it
(perhaps because they have all closed the file, or exited), the read
returns end-of-file.  Writing to a pipe or FIFO that doesn't have a
reading process is treated as an error condition; it generates a
<CODE>SIGPIPE</CODE> signal, and fails with error code <CODE>EPIPE</CODE> if the
signal is handled or blocked.
<P>
Neither pipes nor FIFO special files allow file positioning.  Both
reading and writing operations happen sequentially; reading from the
beginning of the file and writing at the end.
<P>
<A NAME="IDX875"></A>
<A NAME="IDX876"></A>
<A NAME="IDX877"></A>
<H2><A NAME="SEC212" HREF="library_toc.html#SEC212" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC212">Creating a Pipe</A></H2>
<P>
The primitive for creating a pipe is the <CODE>pipe</CODE> function.  This
creates both the reading and writing ends of the pipe.  It is not very
useful for a single process to use a pipe to talk to itself.  In typical
use, a process creates a pipe just before it forks one or more child
processes (see section <A HREF="library_23.html#SEC405" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_23.html#SEC405">Creating a Process</A>).  The pipe is then used for
communication either between the parent or child processes, or between
two sibling processes.
<P>
The <CODE>pipe</CODE> function is declared in the header file
<TT>`unistd.h'</TT>.
<A NAME="IDX878"></A>
<P>
<A NAME="IDX879"></A>
<U>Function:</U> int <B>pipe</B> <I>(int <VAR>filedes</VAR><TT>[2]</TT>)</I><P>
The <CODE>pipe</CODE> function creates a pipe and puts the file descriptors
for the reading and writing ends of the pipe (respectively) into
<CODE><VAR>filedes</VAR>[0]</CODE> and <CODE><VAR>filedes</VAR>[1]</CODE>.
<P>
An easy way to remember that the input end comes first is that file
descriptor <CODE>0</CODE> is standard input, and file descriptor <CODE>1</CODE> is
standard output.
<P>
If successful, <CODE>pipe</CODE> returns a value of <CODE>0</CODE>.  On failure,
<CODE>-1</CODE> is returned.  The following <CODE>errno</CODE> error conditions are
defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EMFILE</CODE>
<DD>The process has too many files open.
<P>
<DT><CODE>ENFILE</CODE>
<DD>There are too many open files in the entire system.  See section <A HREF="library_2.html#SEC16" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_2.html#SEC16">Error Codes</A>,
for more information about <CODE>ENFILE</CODE>.
</DL>
<P>
Here is an example of a simple program that creates a pipe.  This program
uses the <CODE>fork</CODE> function (see section <A HREF="library_23.html#SEC405" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_23.html#SEC405">Creating a Process</A>) to create
a child process.  The parent process writes data to the pipe, which is
read by the child process.
<P>
<PRE>
#include &#60;sys/types.h&#62;
#include &#60;unistd.h&#62;
#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;

/* Read characters from the pipe and echo them to <CODE>stdout</CODE>.   */

void 
read_from_pipe (int file)
{
  FILE *stream;
  int c;
  stream = fdopen (file, "r");
  while ((c = fgetc (stream)) != EOF)
    putchar (c);
  fclose (stream);
}

/* Write some random text to the pipe.  */

void 
write_to_pipe (int file)
{
  FILE *stream;
  stream = fdopen (file, "w");
  fprintf (stream, "hello, world!\n");
  fprintf (stream, "goodbye, world!\n");
  fclose (stream);
}

int
main (void)
{
  pid_t pid;
  int mypipe[2];

  /* Create the pipe.  */
  if (pipe (mypipe))
    {
      fprintf (stderr, "Pipe failed.\n");
      return EXIT_FAILURE;
    }

  /* Create the child process.  */
  pid = fork ();
  if (pid == (pid_t) 0)
    {
      /* This is the child process.  */
      read_from_pipe (mypipe[0]);
      return EXIT_SUCCESS;
    }
  else if (pid &#60; (pid_t) 0)
    {
      /* The fork failed.  */
      fprintf (stderr, "Fork failed.\n");
      return EXIT_FAILURE;
    }
  else
    {
      /* This is the parent process.  */
      write_to_pipe (mypipe[1]);
      return EXIT_SUCCESS;
    }
}
</PRE>
<P>
<A NAME="IDX880"></A>
<A NAME="IDX881"></A>
<A NAME="IDX882"></A>
<H2><A NAME="SEC213" HREF="library_toc.html#SEC213" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC213">Pipe to a Subprocess</A></H2>
<P>
A common use of pipes is to send data to or receive data from a program
being run as subprocess.  One way of doing this is by using a combination of
<CODE>pipe</CODE> (to create the pipe), <CODE>fork</CODE> (to create the subprocess),
<CODE>dup2</CODE> (to force the subprocess to use the pipe as its standard input
or output channel), and <CODE>exec</CODE> (to execute the new program).  Or,
you can use <CODE>popen</CODE> and <CODE>pclose</CODE>.
<P>
The advantage of using <CODE>popen</CODE> and <CODE>pclose</CODE> is that the
interface is much simpler and easier to use.  But it doesn't offer as
much flexibility as using the low-level functions directly.
<P>
<A NAME="IDX883"></A>
<U>Function:</U> FILE * <B>popen</B> <I>(const char *<VAR>command</VAR>, const char *<VAR>mode</VAR>)</I><P>
The <CODE>popen</CODE> function is closely related to the <CODE>system</CODE>
function; see section <A HREF="library_23.html#SEC402" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_23.html#SEC402">Running a Command</A>.  It executes the shell command
<VAR>command</VAR> as a subprocess.  However, instead of waiting for the
command to complete, it creates a pipe to the subprocess and returns a
stream that corresponds to that pipe.
<P>
If you specify a <VAR>mode</VAR> argument of <CODE>"r"</CODE>, you can read from the 
stream to retrieve data from the standard output channel of the subprocess.
The subprocess inherits its standard input channel from the parent process.
<P>
Similarly, if you specify a <VAR>mode</VAR> argument of <CODE>"w"</CODE>, you can
write to the stream to send data to the standard input channel of the
subprocess.  The subprocess inherits its standard output channel from
the parent process.
<P>
In the event of an error, <CODE>popen</CODE> returns a null pointer.  This
might happen if the pipe or stream cannot be created, if the subprocess
cannot be forked, or if the program cannot be executed.
<P>
<A NAME="IDX884"></A>
<U>Function:</U> int <B>pclose</B> <I>(FILE *<VAR>stream</VAR>)</I><P>
The <CODE>pclose</CODE> function is used to close a stream created by <CODE>popen</CODE>.
It waits for the child process to terminate and returns its status value,
as for the <CODE>system</CODE> function.
<P>
Here is an example showing how to use <CODE>popen</CODE> and <CODE>pclose</CODE> to
filter output through another program, in this case the paging program
<CODE>more</CODE>.
<P>
<PRE>
#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;

void 
write_data (FILE * stream)
{
  int i;
  for (i = 0; i &#60; 100; i++)
    fprintf (stream, "%d\n", i);
  if (ferror (stream))
    {
      fprintf (stderr, "Output to stream failed.\n");
      exit (EXIT_FAILURE);
    }
}

int
main (void)
{
  FILE *output;

  output = popen ("more", "w");
  if (!output)
    {
      fprintf (stderr, "Could not run more.\n");
      return EXIT_FAILURE;
    }
  write_data (output);
  pclose (output);
  return EXIT_SUCCESS;
}
</PRE>
<P>
<A NAME="IDX885"></A>
<A NAME="IDX886"></A>
<H2><A NAME="SEC214" HREF="library_toc.html#SEC214" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC214">FIFO Special Files</A></H2>
<P>
A FIFO special file is similar to a pipe, except that it is created in a
different way.  Instead of being an anonymous communications channel, a
FIFO special file is entered into the file system by calling
<CODE>mkfifo</CODE>.
<P>
Once you have created a FIFO special file in this way, any process can
open it for reading or writing, in the same way as an ordinary file.
However, it has to be open at both ends simultaneously before you can
proceed to do any input or output operations on it.  Opening a FIFO for
reading normally blocks until some other process opens the same FIFO for
writing, and vice versa.
<P>
The <CODE>mkfifo</CODE> function is declared in the header file
<TT>`sys/stat.h'</TT>.
<A NAME="IDX887"></A>
<P>
<A NAME="IDX888"></A>
<U>Function:</U> int <B>mkfifo</B> <I>(const char *<VAR>filename</VAR>, mode_t <VAR>mode</VAR>)</I><P>
The <CODE>mkfifo</CODE> function makes a FIFO special file with name
<VAR>filename</VAR>.  The <VAR>mode</VAR> argument is used to set the file's
permissions; see section <A HREF="library_13.html#SEC207" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html#SEC207">Assigning File Permissions</A>.
<P>
The normal, successful return value from <CODE>mkfifo</CODE> is <CODE>0</CODE>.  In
the case of an error, <CODE>-1</CODE> is returned.  In addition to the usual
file name syntax errors (see section <A HREF="library_10.html#SEC115" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_10.html#SEC115">File Name Errors</A>), the following
<CODE>errno</CODE> error conditions are defined for this function:
<P>
<DL COMPACT>
<DT><CODE>EEXIST</CODE>
<DD>The named file already exists.
<P>
<DT><CODE>ENOSPC</CODE>
<DD>The directory or file system cannot be extended.
<P>
<DT><CODE>EROFS</CODE>
<DD>The directory that would contain the file resides on a read-only file
system.
</DL>
<P>
<H2><A NAME="SEC215" HREF="library_toc.html#SEC215" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC215">Atomicity of Pipe I/O</A></H2>
<P>
Reading or writing pipe data is <DFN>atomic</DFN> if the size of data written
is less than <CODE>PIPE_BUF</CODE>.  This means that the data transfer seems
to be an instantaneous unit, in that nothing else in the system can
observe a state in which it is partially complete.  Atomic I/O may not
begin right away (it may need to wait for buffer space or for data), but
once it does begin, it finishes immediately.
<P>
Reading or writing a larger amount of data may not be atomic; for
example, output data from other processes sharing the descriptor may be
interspersed.
<P>
See section <A HREF="library_27.html#SEC463" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_27.html#SEC463">Limits on File System Capacity</A>, for information about the <CODE>PIPE_BUF</CODE>
parameter.
<P>Go to the <A HREF="library_13.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html">previous</A>, <A HREF="library_15.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html">next</A> section.<P>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
777欧美精品| 91精品国产免费久久综合| 99精品视频在线观看免费| 日本乱人伦一区| 91麻豆精品国产91久久久更新时间| 久久久亚洲国产美女国产盗摄| 日韩一区中文字幕| 免费成人av在线| 91色乱码一区二区三区| 精品美女一区二区| 亚洲另类在线制服丝袜| 国产精品一二三四五| 欧美无砖砖区免费| 亚洲国产精品激情在线观看| 丝袜亚洲精品中文字幕一区| 91视频xxxx| 欧美三级视频在线| 久久综合给合久久狠狠狠97色69| 国产精品国产自产拍高清av王其 | 亚洲电影一区二区| 国产乱码精品一品二品| 欧美日韩国产区一| 亚洲精品国产一区二区三区四区在线 | 欧美四级电影在线观看| 国产色91在线| 紧缚捆绑精品一区二区| 欧美日本国产一区| 中文字幕免费不卡| 国产成人免费在线视频| 日韩手机在线导航| 天天免费综合色| 在线观看91精品国产入口| 一区在线中文字幕| 国产精品18久久久久久久久久久久 | 欧美中文一区二区三区| 亚洲视频在线观看一区| 亚洲情趣在线观看| 久久久影院官网| 男女性色大片免费观看一区二区| 在线观看91精品国产入口| 日本一区二区三区四区在线视频| 亚洲天堂网中文字| 91女神在线视频| 中文字幕中文在线不卡住| 丁香桃色午夜亚洲一区二区三区| 国产视频视频一区| 国产不卡视频在线播放| 中文字幕第一区第二区| 成人免费看黄yyy456| 国产精品久久久久久久第一福利| 成人免费av在线| 国产精品初高中害羞小美女文| 国产一区二区三区四| 久久蜜桃av一区精品变态类天堂| 国产一区二区日韩精品| 久久久久九九视频| 99久久99久久精品免费看蜜桃 | 在线观看亚洲成人| 国产精品免费久久| av亚洲精华国产精华| 亚洲免费在线播放| 欧美精品乱码久久久久久| 蜜桃在线一区二区三区| 久久久精品蜜桃| 99国产精品久| 婷婷一区二区三区| 26uuu亚洲综合色欧美| 盗摄精品av一区二区三区| 亚洲色图20p| 91精品午夜视频| 国产麻豆成人传媒免费观看| 亚洲天堂网中文字| 欧美日韩一级视频| 日本亚洲三级在线| 国产亚洲欧美日韩日本| 色老汉av一区二区三区| 蜜臀久久久久久久| 国产精品久久久久久久岛一牛影视| 国产91富婆露脸刺激对白| 亚洲激情自拍偷拍| 精品国产成人系列| av在线免费不卡| 国产精品综合二区| 视频一区二区国产| 亚洲精品视频观看| 国产精品每日更新在线播放网址| 91精品国产综合久久久久久| 色综合天天性综合| 成人午夜视频免费看| 韩国v欧美v日本v亚洲v| 日韩精品欧美精品| 亚洲一区二区三区自拍| 亚洲日本va午夜在线影院| 国产亚洲精品aa午夜观看| 欧美电影精品一区二区| 91精品国产一区二区三区香蕉| 色婷婷精品大在线视频| voyeur盗摄精品| 成人av在线资源网站| 国产黄人亚洲片| 国产乱子轮精品视频| 久久狠狠亚洲综合| 蜜臀av一区二区| 日本不卡视频在线观看| 日本免费新一区视频| 日韩成人av影视| 天天综合天天综合色| 五月天精品一区二区三区| 午夜一区二区三区视频| 亚洲高清视频在线| 婷婷成人综合网| 日韩经典一区二区| 免费视频最近日韩| 国产在线视频一区二区| 国产91在线观看丝袜| 成人深夜福利app| 99re成人在线| 精品污污网站免费看| 在线成人免费视频| 日韩三级免费观看| 久久午夜免费电影| 国产精品精品国产色婷婷| 亚洲色图一区二区| 午夜电影网亚洲视频| 久色婷婷小香蕉久久| 国产高清在线观看免费不卡| 97se亚洲国产综合自在线观| 色综合天天综合网天天看片| 欧美男男青年gay1069videost| 日韩一区二区三区四区| 久久久久久久久久久久电影| 中文字幕在线视频一区| 一区二区三区在线视频播放 | 欧美日韩亚洲高清一区二区| 欧美美女一区二区在线观看| 精品三级在线观看| 亚洲欧洲色图综合| 五月开心婷婷久久| 国产成人午夜精品5599| 在线亚洲免费视频| 日韩一区二区在线观看| 国产精品久久久久久久久快鸭| 亚洲一区二区美女| 国产老女人精品毛片久久| 91丝袜美腿高跟国产极品老师| 欧美日韩免费一区二区三区视频 | 3atv一区二区三区| 国产丝袜在线精品| 亚洲成人综合视频| 国产传媒久久文化传媒| 欧美日韩一区二区在线观看视频| 日韩一区二区三区免费看| 18涩涩午夜精品.www| 另类小说综合欧美亚洲| 色婷婷综合久久久久中文| 精品国产一二三| 亚洲第一电影网| 成人看片黄a免费看在线| 欧美一级二级三级蜜桃| 亚洲婷婷在线视频| 国产精品综合av一区二区国产馆| 欧美丝袜自拍制服另类| 欧美国产禁国产网站cc| 青青草91视频| 欧美色老头old∨ideo| 中文字幕一区二区三区蜜月| 乱一区二区av| 欧美久久久久久久久中文字幕| 亚洲欧洲日本在线| 国内精品伊人久久久久影院对白| 欧美午夜一区二区三区| 国产精品国模大尺度视频| 韩国在线一区二区| 91精品免费观看| 亚洲午夜激情av| 97超碰欧美中文字幕| 国产欧美日韩在线观看| 蜜桃传媒麻豆第一区在线观看| 欧美午夜电影一区| 亚洲精品少妇30p| 色综合久久88色综合天天6| 国产精品免费观看视频| 国产精品亚洲一区二区三区妖精 | 欧美国产亚洲另类动漫| 精品写真视频在线观看| 欧美一二三四区在线| 午夜成人免费电影| 欧美精品18+| 亚洲成人综合网站| 欧美日韩精品一区二区在线播放 | 亚洲精品午夜久久久| 99久久久免费精品国产一区二区| 日本一区二区三区四区在线视频 | 亚洲天堂成人在线观看| 成人影视亚洲图片在线| 国产欧美日韩精品在线| 国产99一区视频免费| 中文字幕中文乱码欧美一区二区| 成人av午夜电影| 亚洲激情五月婷婷|