cat
shuai@ubuntu:~/Desktop$ cat sun.c -n|head -10|tail -5
shuai@ubuntu:~/Desktop$ cat sun.c -n
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <zconf.h>
4 #include <cstring>
5
6 int main() {
7
8 // 创建无名管道
9 int fd[2];
10 if (pipe(fd) == -1)
11 exit(1);
12
13 // 管道传递信息
14 char msgSend[] = "我在写呢";
15 char msgRecv[32];
16
17 int pid = fork();
18
19 if (pid == 0) {
20 // 子进程
21 close(fd[1]); // 关闭管道写入端,准备读
22 printf("before read data from pipe!\n");
23 read(fd[0], msgRecv, strlen(msgSend)); // 把信息读入msgRecv
24 printf("read [%s] from pipe\n", msgRecv);
25 } else {
26 // 父进程
27 close(fd[0]); // 关闭管道读取端,准备写
28 printf("Parent sleeping ......\n");
29 sleep(3); // 迫使子进程先执行
30 printf("Parent wake up !\n");
31 write(fd[1], msgSend, strlen(msgSend));
32 wait(0);
33 }
34 exit(0);
35 }
shuai@ubuntu:~/Desktop$ cat sun.c -n|head -10|tail -5
6 int main() {
7
8 // 创建无名管道
9 int fd[2];
10 if (pipe(fd) == -1)
sed
shuai@ubuntu:~/Desktop$ sed -n '6,10p' sun.c|cat -n
1 int main() {
2
3 // 创建无名管道
4 int fd[2];
5 if (pipe(fd) == -1)
shuai@ubuntu:~/Desktop$
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。