| 函数名 |
pipe |
| 调用语法 |
pipe (infile, outfile); |
| 解说 |
与fork合用,给父进程和子进程提供通信的方式。送到outfile文件变量的信息可以通过infile文件变量读取。步骤: 1、调用pipe 2、用fork将程序分成父进程和子进程 3、一个进程关掉infile,另一个关掉outfile |
| 例子 |
pipe (INPUT, OUTPUT); $retval = fork(); if ($retval != 0) { # this is the parent process close (INPUT); print ("Enter a line of input:\n"); $line = <STDIN>; print OUTPUT ($line); } else { # this is the child process close (OUTPUT); $line = <INPUT>; print ($line); exit (0); }
|
| 结果输出 |
$ program Enter a line of input: Here is a test line Here is a test line $ |